Merge branch 'jc/doc-submitting-patches-choice-of-base'
[git/debian.git] / builtin / add.c
bloba010b2c325ffbec07fbd6b90a59f6582640b81ef
1 /*
2 * "git add" builtin command
4 * Copyright (C) 2006 Linus Torvalds
5 */
6 #define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "config.h"
9 #include "builtin.h"
10 #include "lockfile.h"
11 #include "dir.h"
12 #include "pathspec.h"
13 #include "exec-cmd.h"
14 #include "cache-tree.h"
15 #include "run-command.h"
16 #include "parse-options.h"
17 #include "diff.h"
18 #include "diffcore.h"
19 #include "revision.h"
20 #include "bulk-checkin.h"
21 #include "strvec.h"
22 #include "submodule.h"
23 #include "add-interactive.h"
25 static const char * const builtin_add_usage[] = {
26 N_("git add [<options>] [--] <pathspec>..."),
27 NULL
29 static int patch_interactive, add_interactive, edit_interactive;
30 static int take_worktree_changes;
31 static int add_renormalize;
32 static int pathspec_file_nul;
33 static int include_sparse;
34 static const char *pathspec_from_file;
35 static int legacy_stash_p; /* support for the scripted `git stash` */
37 struct update_callback_data {
38 int flags;
39 int add_errors;
42 static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
44 int i, ret = 0;
46 for (i = 0; i < active_nr; i++) {
47 struct cache_entry *ce = active_cache[i];
48 int err;
50 if (!include_sparse &&
51 (ce_skip_worktree(ce) ||
52 !path_in_sparse_checkout(ce->name, &the_index)))
53 continue;
55 if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
56 continue;
58 if (!show_only)
59 err = chmod_cache_entry(ce, flip);
60 else
61 err = S_ISREG(ce->ce_mode) ? 0 : -1;
63 if (err < 0)
64 ret = error(_("cannot chmod %cx '%s'"), flip, ce->name);
67 return ret;
70 static int fix_unmerged_status(struct diff_filepair *p,
71 struct update_callback_data *data)
73 if (p->status != DIFF_STATUS_UNMERGED)
74 return p->status;
75 if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
77 * This is not an explicit add request, and the
78 * path is missing from the working tree (deleted)
80 return DIFF_STATUS_DELETED;
81 else
83 * Either an explicit add request, or path exists
84 * in the working tree. An attempt to explicitly
85 * add a path that does not exist in the working tree
86 * will be caught as an error by the caller immediately.
88 return DIFF_STATUS_MODIFIED;
91 static void update_callback(struct diff_queue_struct *q,
92 struct diff_options *opt, void *cbdata)
94 int i;
95 struct update_callback_data *data = cbdata;
97 for (i = 0; i < q->nr; i++) {
98 struct diff_filepair *p = q->queue[i];
99 const char *path = p->one->path;
101 if (!include_sparse && !path_in_sparse_checkout(path, &the_index))
102 continue;
104 switch (fix_unmerged_status(p, data)) {
105 default:
106 die(_("unexpected diff status %c"), p->status);
107 case DIFF_STATUS_MODIFIED:
108 case DIFF_STATUS_TYPE_CHANGED:
109 if (add_file_to_index(&the_index, path, data->flags)) {
110 if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
111 die(_("updating files failed"));
112 data->add_errors++;
114 break;
115 case DIFF_STATUS_DELETED:
116 if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
117 break;
118 if (!(data->flags & ADD_CACHE_PRETEND))
119 remove_file_from_index(&the_index, path);
120 if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
121 printf(_("remove '%s'\n"), path);
122 break;
127 int add_files_to_cache(const char *prefix,
128 const struct pathspec *pathspec, int flags)
130 struct update_callback_data data;
131 struct rev_info rev;
133 memset(&data, 0, sizeof(data));
134 data.flags = flags;
136 repo_init_revisions(the_repository, &rev, prefix);
137 setup_revisions(0, NULL, &rev, NULL);
138 if (pathspec)
139 copy_pathspec(&rev.prune_data, pathspec);
140 rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
141 rev.diffopt.format_callback = update_callback;
142 rev.diffopt.format_callback_data = &data;
143 rev.diffopt.flags.override_submodule_config = 1;
144 rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
145 run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
146 clear_pathspec(&rev.prune_data);
147 return !!data.add_errors;
150 static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
152 int i, retval = 0;
154 for (i = 0; i < active_nr; i++) {
155 struct cache_entry *ce = active_cache[i];
157 if (!include_sparse &&
158 (ce_skip_worktree(ce) ||
159 !path_in_sparse_checkout(ce->name, &the_index)))
160 continue;
161 if (ce_stage(ce))
162 continue; /* do not touch unmerged paths */
163 if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
164 continue; /* do not touch non blobs */
165 if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
166 continue;
167 retval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE);
170 return retval;
173 static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, int prefix)
175 char *seen;
176 int i;
177 struct dir_entry **src, **dst;
179 seen = xcalloc(pathspec->nr, 1);
181 src = dst = dir->entries;
182 i = dir->nr;
183 while (--i >= 0) {
184 struct dir_entry *entry = *src++;
185 if (dir_path_match(&the_index, entry, pathspec, prefix, seen))
186 *dst++ = entry;
188 dir->nr = dst - dir->entries;
189 add_pathspec_matches_against_index(pathspec, &the_index, seen,
190 PS_IGNORE_SKIP_WORKTREE);
191 return seen;
194 static int refresh(int verbose, const struct pathspec *pathspec)
196 char *seen;
197 int i, ret = 0;
198 char *skip_worktree_seen = NULL;
199 struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
200 int flags = REFRESH_IGNORE_SKIP_WORKTREE |
201 (verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);
203 seen = xcalloc(pathspec->nr, 1);
204 refresh_index(&the_index, flags, pathspec, seen,
205 _("Unstaged changes after refreshing the index:"));
206 for (i = 0; i < pathspec->nr; i++) {
207 if (!seen[i]) {
208 const char *path = pathspec->items[i].original;
210 if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
211 !path_in_sparse_checkout(path, &the_index)) {
212 string_list_append(&only_match_skip_worktree,
213 pathspec->items[i].original);
214 } else {
215 die(_("pathspec '%s' did not match any files"),
216 pathspec->items[i].original);
221 if (only_match_skip_worktree.nr) {
222 advise_on_updating_sparse_paths(&only_match_skip_worktree);
223 ret = 1;
226 free(seen);
227 free(skip_worktree_seen);
228 string_list_clear(&only_match_skip_worktree, 0);
229 return ret;
232 int run_add_interactive(const char *revision, const char *patch_mode,
233 const struct pathspec *pathspec)
235 int status, i;
236 struct strvec argv = STRVEC_INIT;
237 int use_builtin_add_i =
238 git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
240 if (use_builtin_add_i < 0) {
241 int experimental;
242 if (!git_config_get_bool("add.interactive.usebuiltin",
243 &use_builtin_add_i))
244 ; /* ok */
245 else if (!git_config_get_bool("feature.experimental", &experimental) &&
246 experimental)
247 use_builtin_add_i = 1;
250 if (use_builtin_add_i == 1) {
251 enum add_p_mode mode;
253 if (!patch_mode)
254 return !!run_add_i(the_repository, pathspec);
256 if (!strcmp(patch_mode, "--patch"))
257 mode = ADD_P_ADD;
258 else if (!strcmp(patch_mode, "--patch=stash"))
259 mode = ADD_P_STASH;
260 else if (!strcmp(patch_mode, "--patch=reset"))
261 mode = ADD_P_RESET;
262 else if (!strcmp(patch_mode, "--patch=checkout"))
263 mode = ADD_P_CHECKOUT;
264 else if (!strcmp(patch_mode, "--patch=worktree"))
265 mode = ADD_P_WORKTREE;
266 else
267 die("'%s' not supported", patch_mode);
269 return !!run_add_p(the_repository, mode, revision, pathspec);
272 strvec_push(&argv, "add--interactive");
273 if (patch_mode)
274 strvec_push(&argv, patch_mode);
275 if (revision)
276 strvec_push(&argv, revision);
277 strvec_push(&argv, "--");
278 for (i = 0; i < pathspec->nr; i++)
279 /* pass original pathspec, to be re-parsed */
280 strvec_push(&argv, pathspec->items[i].original);
282 status = run_command_v_opt(argv.v, RUN_GIT_CMD);
283 strvec_clear(&argv);
284 return status;
287 int interactive_add(const char **argv, const char *prefix, int patch)
289 struct pathspec pathspec;
291 parse_pathspec(&pathspec, 0,
292 PATHSPEC_PREFER_FULL |
293 PATHSPEC_SYMLINK_LEADING_PATH |
294 PATHSPEC_PREFIX_ORIGIN,
295 prefix, argv);
297 return run_add_interactive(NULL,
298 patch ? "--patch" : NULL,
299 &pathspec);
302 static int edit_patch(int argc, const char **argv, const char *prefix)
304 char *file = git_pathdup("ADD_EDIT.patch");
305 struct child_process child = CHILD_PROCESS_INIT;
306 struct rev_info rev;
307 int out;
308 struct stat st;
310 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
312 if (read_cache() < 0)
313 die(_("Could not read the index"));
315 repo_init_revisions(the_repository, &rev, prefix);
316 rev.diffopt.context = 7;
318 argc = setup_revisions(argc, argv, &rev, NULL);
319 rev.diffopt.output_format = DIFF_FORMAT_PATCH;
320 rev.diffopt.use_color = 0;
321 rev.diffopt.flags.ignore_dirty_submodules = 1;
322 out = xopen(file, O_CREAT | O_WRONLY | O_TRUNC, 0666);
323 rev.diffopt.file = xfdopen(out, "w");
324 rev.diffopt.close_file = 1;
325 if (run_diff_files(&rev, 0))
326 die(_("Could not write patch"));
328 if (launch_editor(file, NULL, NULL))
329 die(_("editing patch failed"));
331 if (stat(file, &st))
332 die_errno(_("Could not stat '%s'"), file);
333 if (!st.st_size)
334 die(_("Empty patch. Aborted."));
336 child.git_cmd = 1;
337 strvec_pushl(&child.args, "apply", "--recount", "--cached", file,
338 NULL);
339 if (run_command(&child))
340 die(_("Could not apply '%s'"), file);
342 unlink(file);
343 free(file);
344 return 0;
347 static const char ignore_error[] =
348 N_("The following paths are ignored by one of your .gitignore files:\n");
350 static int verbose, show_only, ignored_too, refresh_only;
351 static int ignore_add_errors, intent_to_add, ignore_missing;
352 static int warn_on_embedded_repo = 1;
354 #define ADDREMOVE_DEFAULT 1
355 static int addremove = ADDREMOVE_DEFAULT;
356 static int addremove_explicit = -1; /* unspecified */
358 static char *chmod_arg;
360 static int ignore_removal_cb(const struct option *opt, const char *arg, int unset)
362 /* if we are told to ignore, we are not adding removals */
363 *(int *)opt->value = !unset ? 0 : 1;
364 return 0;
367 static struct option builtin_add_options[] = {
368 OPT__DRY_RUN(&show_only, N_("dry run")),
369 OPT__VERBOSE(&verbose, N_("be verbose")),
370 OPT_GROUP(""),
371 OPT_BOOL('i', "interactive", &add_interactive, N_("interactive picking")),
372 OPT_BOOL('p', "patch", &patch_interactive, N_("select hunks interactively")),
373 OPT_BOOL('e', "edit", &edit_interactive, N_("edit current diff and apply")),
374 OPT__FORCE(&ignored_too, N_("allow adding otherwise ignored files"), 0),
375 OPT_BOOL('u', "update", &take_worktree_changes, N_("update tracked files")),
376 OPT_BOOL(0, "renormalize", &add_renormalize, N_("renormalize EOL of tracked files (implies -u)")),
377 OPT_BOOL('N', "intent-to-add", &intent_to_add, N_("record only the fact that the path will be added later")),
378 OPT_BOOL('A', "all", &addremove_explicit, N_("add changes from all tracked and untracked files")),
379 OPT_CALLBACK_F(0, "ignore-removal", &addremove_explicit,
380 NULL /* takes no arguments */,
381 N_("ignore paths removed in the working tree (same as --no-all)"),
382 PARSE_OPT_NOARG, ignore_removal_cb),
383 OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
384 OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
385 OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
386 OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
387 OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
388 N_("override the executable bit of the listed files")),
389 OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
390 N_("warn when adding an embedded repository")),
391 OPT_HIDDEN_BOOL(0, "legacy-stash-p", &legacy_stash_p,
392 N_("backend for `git stash -p`")),
393 OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
394 OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
395 OPT_END(),
398 static int add_config(const char *var, const char *value, void *cb)
400 if (!strcmp(var, "add.ignoreerrors") ||
401 !strcmp(var, "add.ignore-errors")) {
402 ignore_add_errors = git_config_bool(var, value);
403 return 0;
406 return git_default_config(var, value, cb);
409 static const char embedded_advice[] = N_(
410 "You've added another git repository inside your current repository.\n"
411 "Clones of the outer repository will not contain the contents of\n"
412 "the embedded repository and will not know how to obtain it.\n"
413 "If you meant to add a submodule, use:\n"
414 "\n"
415 " git submodule add <url> %s\n"
416 "\n"
417 "If you added this path by mistake, you can remove it from the\n"
418 "index with:\n"
419 "\n"
420 " git rm --cached %s\n"
421 "\n"
422 "See \"git help submodule\" for more information."
425 static void check_embedded_repo(const char *path)
427 struct strbuf name = STRBUF_INIT;
428 static int adviced_on_embedded_repo = 0;
430 if (!warn_on_embedded_repo)
431 return;
432 if (!ends_with(path, "/"))
433 return;
435 /* Drop trailing slash for aesthetics */
436 strbuf_addstr(&name, path);
437 strbuf_strip_suffix(&name, "/");
439 warning(_("adding embedded git repository: %s"), name.buf);
440 if (!adviced_on_embedded_repo &&
441 advice_enabled(ADVICE_ADD_EMBEDDED_REPO)) {
442 advise(embedded_advice, name.buf, name.buf);
443 adviced_on_embedded_repo = 1;
446 strbuf_release(&name);
449 static int add_files(struct dir_struct *dir, int flags)
451 int i, exit_status = 0;
452 struct string_list matched_sparse_paths = STRING_LIST_INIT_NODUP;
454 if (dir->ignored_nr) {
455 fprintf(stderr, _(ignore_error));
456 for (i = 0; i < dir->ignored_nr; i++)
457 fprintf(stderr, "%s\n", dir->ignored[i]->name);
458 if (advice_enabled(ADVICE_ADD_IGNORED_FILE))
459 advise(_("Use -f if you really want to add them.\n"
460 "Turn this message off by running\n"
461 "\"git config advice.addIgnoredFile false\""));
462 exit_status = 1;
465 for (i = 0; i < dir->nr; i++) {
466 if (!include_sparse &&
467 !path_in_sparse_checkout(dir->entries[i]->name, &the_index)) {
468 string_list_append(&matched_sparse_paths,
469 dir->entries[i]->name);
470 continue;
472 if (add_file_to_index(&the_index, dir->entries[i]->name, flags)) {
473 if (!ignore_add_errors)
474 die(_("adding files failed"));
475 exit_status = 1;
476 } else {
477 check_embedded_repo(dir->entries[i]->name);
481 if (matched_sparse_paths.nr) {
482 advise_on_updating_sparse_paths(&matched_sparse_paths);
483 exit_status = 1;
486 string_list_clear(&matched_sparse_paths, 0);
488 return exit_status;
491 int cmd_add(int argc, const char **argv, const char *prefix)
493 int exit_status = 0;
494 struct pathspec pathspec;
495 struct dir_struct dir = DIR_INIT;
496 int flags;
497 int add_new_files;
498 int require_pathspec;
499 char *seen = NULL;
500 struct lock_file lock_file = LOCK_INIT;
502 git_config(add_config, NULL);
504 argc = parse_options(argc, argv, prefix, builtin_add_options,
505 builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
506 if (patch_interactive)
507 add_interactive = 1;
508 if (add_interactive) {
509 if (show_only)
510 die(_("--dry-run is incompatible with --interactive/--patch"));
511 if (pathspec_from_file)
512 die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
513 exit(interactive_add(argv + 1, prefix, patch_interactive));
515 if (legacy_stash_p) {
516 struct pathspec pathspec;
518 parse_pathspec(&pathspec, 0,
519 PATHSPEC_PREFER_FULL |
520 PATHSPEC_SYMLINK_LEADING_PATH |
521 PATHSPEC_PREFIX_ORIGIN,
522 prefix, argv);
524 return run_add_interactive(NULL, "--patch=stash", &pathspec);
527 if (edit_interactive) {
528 if (pathspec_from_file)
529 die(_("--pathspec-from-file is incompatible with --edit"));
530 return(edit_patch(argc, argv, prefix));
532 argc--;
533 argv++;
535 if (0 <= addremove_explicit)
536 addremove = addremove_explicit;
537 else if (take_worktree_changes && ADDREMOVE_DEFAULT)
538 addremove = 0; /* "-u" was given but not "-A" */
540 if (addremove && take_worktree_changes)
541 die(_("-A and -u are mutually incompatible"));
543 if (!show_only && ignore_missing)
544 die(_("Option --ignore-missing can only be used together with --dry-run"));
546 if (chmod_arg && ((chmod_arg[0] != '-' && chmod_arg[0] != '+') ||
547 chmod_arg[1] != 'x' || chmod_arg[2]))
548 die(_("--chmod param '%s' must be either -x or +x"), chmod_arg);
550 add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize;
551 require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
553 prepare_repo_settings(the_repository);
554 the_repository->settings.command_requires_full_index = 0;
556 hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
559 * Check the "pathspec '%s' did not match any files" block
560 * below before enabling new magic.
562 parse_pathspec(&pathspec, PATHSPEC_ATTR,
563 PATHSPEC_PREFER_FULL |
564 PATHSPEC_SYMLINK_LEADING_PATH,
565 prefix, argv);
567 if (pathspec_from_file) {
568 if (pathspec.nr)
569 die(_("--pathspec-from-file is incompatible with pathspec arguments"));
571 parse_pathspec_file(&pathspec, PATHSPEC_ATTR,
572 PATHSPEC_PREFER_FULL |
573 PATHSPEC_SYMLINK_LEADING_PATH,
574 prefix, pathspec_from_file, pathspec_file_nul);
575 } else if (pathspec_file_nul) {
576 die(_("--pathspec-file-nul requires --pathspec-from-file"));
579 if (require_pathspec && pathspec.nr == 0) {
580 fprintf(stderr, _("Nothing specified, nothing added.\n"));
581 if (advice_enabled(ADVICE_ADD_EMPTY_PATHSPEC))
582 advise( _("Maybe you wanted to say 'git add .'?\n"
583 "Turn this message off by running\n"
584 "\"git config advice.addEmptyPathspec false\""));
585 return 0;
588 if (!take_worktree_changes && addremove_explicit < 0 && pathspec.nr)
589 /* Turn "git add pathspec..." to "git add -A pathspec..." */
590 addremove = 1;
592 flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
593 (show_only ? ADD_CACHE_PRETEND : 0) |
594 (intent_to_add ? ADD_CACHE_INTENT : 0) |
595 (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) |
596 (!(addremove || take_worktree_changes)
597 ? ADD_CACHE_IGNORE_REMOVAL : 0));
599 if (read_cache_preload(&pathspec) < 0)
600 die(_("index file corrupt"));
602 die_in_unpopulated_submodule(&the_index, prefix);
603 die_path_inside_submodule(&the_index, &pathspec);
605 if (add_new_files) {
606 int baselen;
608 /* Set up the default git porcelain excludes */
609 if (!ignored_too) {
610 dir.flags |= DIR_COLLECT_IGNORED;
611 setup_standard_excludes(&dir);
614 /* This picks up the paths that are not tracked */
615 baselen = fill_directory(&dir, &the_index, &pathspec);
616 if (pathspec.nr)
617 seen = prune_directory(&dir, &pathspec, baselen);
620 if (refresh_only) {
621 exit_status |= refresh(verbose, &pathspec);
622 goto finish;
625 if (pathspec.nr) {
626 int i;
627 char *skip_worktree_seen = NULL;
628 struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
630 if (!seen)
631 seen = find_pathspecs_matching_against_index(&pathspec,
632 &the_index, PS_IGNORE_SKIP_WORKTREE);
635 * file_exists() assumes exact match
637 GUARD_PATHSPEC(&pathspec,
638 PATHSPEC_FROMTOP |
639 PATHSPEC_LITERAL |
640 PATHSPEC_GLOB |
641 PATHSPEC_ICASE |
642 PATHSPEC_EXCLUDE);
644 for (i = 0; i < pathspec.nr; i++) {
645 const char *path = pathspec.items[i].match;
647 if (pathspec.items[i].magic & PATHSPEC_EXCLUDE)
648 continue;
649 if (seen[i])
650 continue;
652 if (!include_sparse &&
653 matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
654 string_list_append(&only_match_skip_worktree,
655 pathspec.items[i].original);
656 continue;
659 /* Don't complain at 'git add .' on empty repo */
660 if (!path[0])
661 continue;
663 if ((pathspec.items[i].magic & (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
664 !file_exists(path)) {
665 if (ignore_missing) {
666 int dtype = DT_UNKNOWN;
667 if (is_excluded(&dir, &the_index, path, &dtype))
668 dir_add_ignored(&dir, &the_index,
669 path, pathspec.items[i].len);
670 } else
671 die(_("pathspec '%s' did not match any files"),
672 pathspec.items[i].original);
677 if (only_match_skip_worktree.nr) {
678 advise_on_updating_sparse_paths(&only_match_skip_worktree);
679 exit_status = 1;
682 free(seen);
683 free(skip_worktree_seen);
684 string_list_clear(&only_match_skip_worktree, 0);
687 plug_bulk_checkin();
689 if (add_renormalize)
690 exit_status |= renormalize_tracked_files(&pathspec, flags);
691 else
692 exit_status |= add_files_to_cache(prefix, &pathspec, flags);
694 if (add_new_files)
695 exit_status |= add_files(&dir, flags);
697 if (chmod_arg && pathspec.nr)
698 exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only);
699 unplug_bulk_checkin();
701 finish:
702 if (write_locked_index(&the_index, &lock_file,
703 COMMIT_LOCK | SKIP_IF_UNCHANGED))
704 die(_("Unable to write new index file"));
706 dir_clear(&dir);
707 UNLEAK(pathspec);
708 return exit_status;