diff options
author | Matheus Tavares <matheus.bernardino@usp.br> | 2021-02-22 22:10:35 -0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-02-24 12:14:51 -0800 |
commit | 9ebd7fe15869910c81c42290bd80296664597dec (patch) | |
tree | 468e6cdeefb78a29eff87e4e7d649cb188a5f286 /builtin/add.c | |
parent | add: mark --chmod error string for translation (diff) | |
download | tgif-9ebd7fe15869910c81c42290bd80296664597dec.tar.xz |
add: propagate --chmod errors to exit status
If `add` encounters an error while applying the --chmod changes, it
prints a message to stderr, but exits with a success code. This might
have been an oversight, as the command does exit with a non-zero code in
other situations where it cannot (or refuses to) update all of the
requested paths (e.g. when some of the given paths are ignored). So make
the exit behavior more consistent by also propagating --chmod errors to
the exit status.
Note: the test "all statuses changed in folder if . is given" uses paths
added by previous test cases, some of which might be symbolic links.
Because `git add --chmod` will now fail with such paths, this test would
depend on whether all the previous tests were executed, or only some
of them. Avoid that by running the test on a fresh repo with only
regular files.
Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Reviewed-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/add.c')
-rw-r--r-- | builtin/add.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/builtin/add.c b/builtin/add.c index 0c5f53c0bb..ea762a41e3 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -38,9 +38,9 @@ struct update_callback_data { int add_errors; }; -static void chmod_pathspec(struct pathspec *pathspec, char flip, int show_only) +static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only) { - int i; + int i, ret = 0; for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; @@ -55,8 +55,10 @@ static void chmod_pathspec(struct pathspec *pathspec, char flip, int show_only) err = S_ISREG(ce->ce_mode) ? 0 : -1; if (err < 0) - error(_("cannot chmod %cx '%s'"), flip, ce->name); + ret = error(_("cannot chmod %cx '%s'"), flip, ce->name); } + + return ret; } static int fix_unmerged_status(struct diff_filepair *p, @@ -615,7 +617,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) exit_status |= add_files(&dir, flags); if (chmod_arg && pathspec.nr) - chmod_pathspec(&pathspec, chmod_arg[0], show_only); + exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only); unplug_bulk_checkin(); finish: |