]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/add.c
add: propagate --chmod errors to exit status
[thirdparty/git.git] / builtin / add.c
index 26b6ced09ea26d7eda4c63a930354d2bb580a547..ea762a41e3a2d2c41718de2e97c6a0e6031ce91c 100644 (file)
@@ -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,
@@ -239,7 +247,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,
        return status;
 }
 
-int interactive_add(int argc, const char **argv, const char *prefix, int patch)
+int interactive_add(const char **argv, const char *prefix, int patch)
 {
        struct pathspec pathspec;
 
@@ -451,7 +459,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        if (add_interactive) {
                if (pathspec_from_file)
                        die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
-               exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));
+               exit(interactive_add(argv + 1, prefix, patch_interactive));
        }
        if (legacy_stash_p) {
                struct pathspec pathspec;
@@ -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: