@@ -26,6 +26,7 @@ static const char * const builtin_add_usage[] = {
2626};
2727static int patch_interactive , add_interactive , edit_interactive ;
2828static int take_worktree_changes ;
29+ static int add_renormalize ;
2930
3031struct update_callback_data {
3132 int flags ;
@@ -123,6 +124,25 @@ int add_files_to_cache(const char *prefix,
123124 return !!data .add_errors ;
124125}
125126
127+ static int renormalize_tracked_files (const struct pathspec * pathspec , int flags )
128+ {
129+ int i , retval = 0 ;
130+
131+ for (i = 0 ; i < active_nr ; i ++ ) {
132+ struct cache_entry * ce = active_cache [i ];
133+
134+ if (ce_stage (ce ))
135+ continue ; /* do not touch unmerged paths */
136+ if (!S_ISREG (ce -> ce_mode ) && !S_ISLNK (ce -> ce_mode ))
137+ continue ; /* do not touch non blobs */
138+ if (pathspec && !ce_path_match (ce , pathspec , NULL ))
139+ continue ;
140+ retval |= add_file_to_cache (ce -> name , flags | HASH_RENORMALIZE );
141+ }
142+
143+ return retval ;
144+ }
145+
126146static char * prune_directory (struct dir_struct * dir , struct pathspec * pathspec , int prefix )
127147{
128148 char * seen ;
@@ -276,6 +296,7 @@ static struct option builtin_add_options[] = {
276296 OPT_BOOL ('e' , "edit" , & edit_interactive , N_ ("edit current diff and apply" )),
277297 OPT__FORCE (& ignored_too , N_ ("allow adding otherwise ignored files" )),
278298 OPT_BOOL ('u' , "update" , & take_worktree_changes , N_ ("update tracked files" )),
299+ OPT_BOOL (0 , "renormalize" , & add_renormalize , N_ ("renormalize EOL of tracked files (implies -u)" )),
279300 OPT_BOOL ('N' , "intent-to-add" , & intent_to_add , N_ ("record only the fact that the path will be added later" )),
280301 OPT_BOOL ('A' , "all" , & addremove_explicit , N_ ("add changes from all tracked and untracked files" )),
281302 { OPTION_CALLBACK , 0 , "ignore-removal" , & addremove_explicit ,
@@ -406,7 +427,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
406427 chmod_arg [1 ] != 'x' || chmod_arg [2 ]))
407428 die (_ ("--chmod param '%s' must be either -x or +x" ), chmod_arg );
408429
409- add_new_files = !take_worktree_changes && !refresh_only ;
430+ add_new_files = !take_worktree_changes && !refresh_only && ! add_renormalize ;
410431 require_pathspec = !(take_worktree_changes || (0 < addremove_explicit ));
411432
412433 hold_locked_index (& lock_file , LOCK_DIE_ON_ERROR );
@@ -500,7 +521,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
500521
501522 plug_bulk_checkin ();
502523
503- exit_status |= add_files_to_cache (prefix , & pathspec , flags );
524+ if (add_renormalize )
525+ exit_status |= renormalize_tracked_files (& pathspec , flags );
526+ else
527+ exit_status |= add_files_to_cache (prefix , & pathspec , flags );
504528
505529 if (add_new_files )
506530 exit_status |= add_files (& dir , flags );
0 commit comments