26
static int take_worktree_changes;
27
28
struct update_callback_data {
29
- int flags;
29
+ int flags, force_mode;
30
int add_errors;
31
};
32
65
die(_("unexpected diff status %c"), p->status);
66
case DIFF_STATUS_MODIFIED:
67
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)) {
70
if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
71
die(_("updating files failed"));
72
data->add_errors++;
84
}
85
}
86
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)
89
{
90
struct update_callback_data data;
91
struct rev_info rev;
92
93
memset(&data, 0, sizeof(data));
94
data.flags = flags;
95
+ data.force_mode = force_mode;
96
97
init_revisions(&rev, prefix);
98
setup_revisions(0, NULL, &rev, NULL);
240
static int addremove = ADDREMOVE_DEFAULT;
241
static int addremove_explicit = -1; /* unspecified */
242
243
+static char *chmod_arg;
244
+
245
static int ignore_removal_cb(const struct option *opt, const char *arg, int unset)
246
{
247
/* if we are told to ignore, we are not adding removals */
267
OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
268
OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
269
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")),
271
OPT_END(),
272
};
273
281
return git_default_config(var, value, cb);
282
}
283
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)
285
{
286
int i, exit_status = 0;
287
294
}
295
296
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)) {
299
if (!ignore_add_errors)
300
die(_("adding files failed"));
301
exit_status = 1;
308
int exit_status = 0;
309
struct pathspec pathspec;
310
struct dir_struct dir;
305
- int flags;
311
+ int flags, force_mode;
312
int add_new_files;
313
int require_pathspec;
314
char *seen = NULL;
342
if (!show_only && ignore_missing)
343
die(_("Option --ignore-missing can only be used together with --dry-run"));
344
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
+
354
add_new_files = !take_worktree_changes && !refresh_only;
355
require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
356
441
442
plug_bulk_checkin();
443
429
- exit_status |= add_files_to_cache(prefix, &pathspec, flags);
444
+ exit_status |= add_files_to_cache(prefix, &pathspec, flags, force_mode);
445
446
if (add_new_files)
432
- exit_status |= add_files(&dir, flags);
447
+ exit_status |= add_files(&dir, flags, force_mode);
448
449
unplug_bulk_checkin();
450