@@ -26,7 +26,7 @@ static int patch_interactive, add_interactive, edit_interactive;
2626static int take_worktree_changes ;
2727
2828struct update_callback_data {
29- int flags ;
29+ int flags , force_mode ;
3030 int add_errors ;
3131};
3232
@@ -65,7 +65,8 @@ static void update_callback(struct diff_queue_struct *q,
6565 die (_ ("unexpected diff status %c" ), p -> status );
6666 case DIFF_STATUS_MODIFIED :
6767 case DIFF_STATUS_TYPE_CHANGED :
68- if (add_file_to_index (& the_index , path , data -> flags )) {
68+ if (add_file_to_index (& the_index , path ,
69+ data -> flags , data -> force_mode )) {
6970 if (!(data -> flags & ADD_CACHE_IGNORE_ERRORS ))
7071 die (_ ("updating files failed" ));
7172 data -> add_errors ++ ;
@@ -83,14 +84,15 @@ static void update_callback(struct diff_queue_struct *q,
8384 }
8485}
8586
86- int add_files_to_cache (const char * prefix ,
87- const struct pathspec * pathspec , int flags )
87+ int add_files_to_cache (const char * prefix , const struct pathspec * pathspec ,
88+ int flags , int force_mode )
8889{
8990 struct update_callback_data data ;
9091 struct rev_info rev ;
9192
9293 memset (& data , 0 , sizeof (data ));
9394 data .flags = flags ;
95+ data .force_mode = force_mode ;
9496
9597 init_revisions (& rev , prefix );
9698 setup_revisions (0 , NULL , & rev , NULL );
@@ -238,6 +240,8 @@ static int ignore_add_errors, intent_to_add, ignore_missing;
238240static int addremove = ADDREMOVE_DEFAULT ;
239241static int addremove_explicit = -1 ; /* unspecified */
240242
243+ static char * chmod_arg ;
244+
241245static int ignore_removal_cb (const struct option * opt , const char * arg , int unset )
242246{
243247 /* if we are told to ignore, we are not adding removals */
@@ -263,6 +267,7 @@ static struct option builtin_add_options[] = {
263267 OPT_BOOL ( 0 , "refresh" , & refresh_only , N_ ("don't add, only refresh the index" )),
264268 OPT_BOOL ( 0 , "ignore-errors" , & ignore_add_errors , N_ ("just skip files which cannot be added because of errors" )),
265269 OPT_BOOL ( 0 , "ignore-missing" , & ignore_missing , N_ ("check if - even missing - files are ignored in dry run" )),
270+ OPT_STRING ( 0 , "chmod" , & chmod_arg , N_ ("(+/-)x" ), N_ ("override the executable bit of the listed files" )),
266271 OPT_END (),
267272};
268273
@@ -276,7 +281,7 @@ static int add_config(const char *var, const char *value, void *cb)
276281 return git_default_config (var , value , cb );
277282}
278283
279- static int add_files (struct dir_struct * dir , int flags )
284+ static int add_files (struct dir_struct * dir , int flags , int force_mode )
280285{
281286 int i , exit_status = 0 ;
282287
@@ -289,7 +294,8 @@ static int add_files(struct dir_struct *dir, int flags)
289294 }
290295
291296 for (i = 0 ; i < dir -> nr ; i ++ )
292- if (add_file_to_cache (dir -> entries [i ]-> name , flags )) {
297+ if (add_file_to_index (& the_index , dir -> entries [i ]-> name ,
298+ flags , force_mode )) {
293299 if (!ignore_add_errors )
294300 die (_ ("adding files failed" ));
295301 exit_status = 1 ;
@@ -302,7 +308,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
302308 int exit_status = 0 ;
303309 struct pathspec pathspec ;
304310 struct dir_struct dir ;
305- int flags ;
311+ int flags , force_mode ;
306312 int add_new_files ;
307313 int require_pathspec ;
308314 char * seen = NULL ;
@@ -336,6 +342,15 @@ int cmd_add(int argc, const char **argv, const char *prefix)
336342 if (!show_only && ignore_missing )
337343 die (_ ("Option --ignore-missing can only be used together with --dry-run" ));
338344
345+ if (!chmod_arg )
346+ force_mode = 0 ;
347+ else if (!strcmp (chmod_arg , "-x" ))
348+ force_mode = 0666 ;
349+ else if (!strcmp (chmod_arg , "+x" ))
350+ force_mode = 0777 ;
351+ else
352+ die (_ ("--chmod param '%s' must be either -x or +x" ), chmod_arg );
353+
339354 add_new_files = !take_worktree_changes && !refresh_only ;
340355 require_pathspec = !(take_worktree_changes || (0 < addremove_explicit ));
341356
@@ -426,10 +441,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
426441
427442 plug_bulk_checkin ();
428443
429- exit_status |= add_files_to_cache (prefix , & pathspec , flags );
444+ exit_status |= add_files_to_cache (prefix , & pathspec , flags , force_mode );
430445
431446 if (add_new_files )
432- exit_status |= add_files (& dir , flags );
447+ exit_status |= add_files (& dir , flags , force_mode );
433448
434449 unplug_bulk_checkin ();
435450
0 commit comments