summaryrefslogtreecommitdiff
path: root/builtin/add.c
diff options
context:
space:
mode:
authorLibravatar Matheus Tavares <matheus.bernardino@usp.br>2021-02-22 22:10:33 -0300
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-02-24 12:14:51 -0800
commitc937d70bfb7661d5122e08758ae0531073a719ed (patch)
tree9f33529e8be9c981f0cb935d10059b879409adfd /builtin/add.c
parentThe tenth batch (diff)
downloadtgif-c937d70bfb7661d5122e08758ae0531073a719ed.tar.xz
add --chmod: don't update index when --dry-run is used
`git add --chmod` applies the mode changes even when `--dry-run` is used. Fix that and add some tests for this option combination. Helped-by: Junio C Hamano <gitster@pobox.com> 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.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/builtin/add.c b/builtin/add.c
index a825887c50..1e33ab81f2 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -38,17 +38,23 @@ struct update_callback_data {
int add_errors;
};
-static void chmod_pathspec(struct pathspec *pathspec, char flip)
+static void chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
{
int i;
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)
+ if (!show_only)
+ err = chmod_cache_entry(ce, flip);
+ else
+ err = S_ISREG(ce->ce_mode) ? 0 : -1;
+
+ if (err < 0)
fprintf(stderr, "cannot chmod %cx '%s'\n", flip, ce->name);
}
}
@@ -609,7 +615,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]);
+ chmod_pathspec(&pathspec, chmod_arg[0], show_only);
unplug_bulk_checkin();
finish: