summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-02-25 16:43:31 -0800
committerJunio C Hamano <gitster@pobox.com>2021-02-25 16:43:31 -0800
commitf277234860b2e5e142ab72d2c288f6fd94bd2219 (patch)
tree7299096feda1b9981f776f7baf606c0456187e76
parentMerge branch 'ds/merge-base-independent' (diff)
parentadd: propagate --chmod errors to exit status (diff)
downloadgit-f277234860b2e5e142ab72d2c288f6fd94bd2219.tar.xz
git-f277234860b2e5e142ab72d2c288f6fd94bd2219.zip
Merge branch 'mt/add-chmod-fixes'
Various fixes on "git add --chmod". * mt/add-chmod-fixes: add: propagate --chmod errors to exit status add: mark --chmod error string for translation add --chmod: don't update index when --dry-run is used
-rw-r--r--builtin/add.c18
-rwxr-xr-xt/t3700-add.sh46
2 files changed, 54 insertions, 10 deletions
diff --git a/builtin/add.c b/builtin/add.c
index a825887c503..ea762a41e3a 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -38,19 +38,27 @@ struct update_callback_data {
int add_errors;
};
-static void chmod_pathspec(struct pathspec *pathspec, char flip)
+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];
+ int err;
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
continue;
- if (chmod_cache_entry(ce, flip) < 0)
- fprintf(stderr, "cannot chmod %cx '%s'\n", flip, ce->name);
+ if (!show_only)
+ err = chmod_cache_entry(ce, flip);
+ else
+ err = S_ISREG(ce->ce_mode) ? 0 : -1;
+
+ if (err < 0)
+ ret = error(_("cannot chmod %cx '%s'"), flip, ce->name);
}
+
+ return ret;
}
static int fix_unmerged_status(struct diff_filepair *p,
@@ -609,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]);
+ exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only);
unplug_bulk_checkin();
finish:
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index dda84004f96..b3b122ff977 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -386,6 +386,36 @@ test_expect_success POSIXPERM 'git add --chmod=[+-]x does not change the working
! test -x foo4
'
+test_expect_success 'git add --chmod fails with non regular files (but updates the other paths)' '
+ git reset --hard &&
+ test_ln_s_add foo foo3 &&
+ touch foo4 &&
+ test_must_fail git add --chmod=+x foo3 foo4 2>stderr &&
+ test_i18ngrep "cannot chmod +x .foo3." stderr &&
+ test_mode_in_index 120000 foo3 &&
+ test_mode_in_index 100755 foo4
+'
+
+test_expect_success 'git add --chmod honors --dry-run' '
+ git reset --hard &&
+ echo foo >foo4 &&
+ git add foo4 &&
+ git add --chmod=+x --dry-run foo4 &&
+ test_mode_in_index 100644 foo4
+'
+
+test_expect_success 'git add --chmod --dry-run reports error for non regular files' '
+ git reset --hard &&
+ test_ln_s_add foo foo4 &&
+ test_must_fail git add --chmod=+x --dry-run foo4 2>stderr &&
+ test_i18ngrep "cannot chmod +x .foo4." stderr
+'
+
+test_expect_success 'git add --chmod --dry-run reports error for unmatched pathspec' '
+ test_must_fail git add --chmod=+x --dry-run nonexistent 2>stderr &&
+ test_i18ngrep "pathspec .nonexistent. did not match any files" stderr
+'
+
test_expect_success 'no file status change if no pathspec is given' '
>foo5 &&
>foo6 &&
@@ -409,11 +439,17 @@ test_expect_success 'no file status change if no pathspec is given in subdir' '
'
test_expect_success 'all statuses changed in folder if . is given' '
- rm -fr empty &&
- git add --chmod=+x . &&
- test $(git ls-files --stage | grep ^100644 | wc -l) -eq 0 &&
- git add --chmod=-x . &&
- test $(git ls-files --stage | grep ^100755 | wc -l) -eq 0
+ git init repo &&
+ (
+ cd repo &&
+ mkdir -p sub/dir &&
+ touch x y z sub/a sub/dir/b &&
+ git add -A &&
+ git add --chmod=+x . &&
+ test $(git ls-files --stage | grep ^100644 | wc -l) -eq 0 &&
+ git add --chmod=-x . &&
+ test $(git ls-files --stage | grep ^100755 | wc -l) -eq 0
+ )
'
test_expect_success CASE_INSENSITIVE_FS 'path is case-insensitive' '