Merge branch 'jk/add-e-kill-editor'
authorJunio C Hamano <gitster@pobox.com>
Fri, 22 May 2015 19:41:55 +0000 (12:41 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 May 2015 19:41:55 +0000 (12:41 -0700)
"git add -e" did not allow the user to abort the operation by
killing the editor.

* jk/add-e-kill-editor:
add: check return value of launch_editor

1  2 
builtin/add.c
diff --combined builtin/add.c
index ee370b059adfd106c70e2c4aa4df50663cb4a8ec,1c7436589e3b44356da9eb319ddc6d75e38f9b68..df5135bf62acabfa9f68793435c1576ba7c1a36a
@@@ -5,7 -5,6 +5,7 @@@
   */
  #include "cache.h"
  #include "builtin.h"
 +#include "lockfile.h"
  #include "dir.h"
  #include "pathspec.h"
  #include "exec_cmd.h"
@@@ -19,7 -18,7 +19,7 @@@
  #include "argv-array.h"
  
  static const char * const builtin_add_usage[] = {
 -      N_("git add [options] [--] <pathspec>..."),
 +      N_("git add [<options>] [--] <pathspec>..."),
        NULL
  };
  static int patch_interactive, add_interactive, edit_interactive;
@@@ -63,7 -62,6 +63,7 @@@ static void update_callback(struct diff
                switch (fix_unmerged_status(p, data)) {
                default:
                        die(_("unexpected diff status %c"), p->status);
 +              case DIFF_STATUS_ADDED:
                case DIFF_STATUS_MODIFIED:
                case DIFF_STATUS_TYPE_CHANGED:
                        if (add_file_to_index(&the_index, path, data->flags)) {
@@@ -182,7 -180,7 +182,7 @@@ static int edit_patch(int argc, const c
        char *file = git_pathdup("ADD_EDIT.patch");
        const char *apply_argv[] = { "apply", "--recount", "--cached",
                NULL, NULL };
 -      struct child_process child;
 +      struct child_process child = CHILD_PROCESS_INIT;
        struct rev_info rev;
        int out;
        struct stat st;
        if (run_diff_files(&rev, 0))
                die(_("Could not write patch"));
  
-       launch_editor(file, NULL, NULL);
+       if (launch_editor(file, NULL, NULL))
+               die(_("editing patch failed"));
  
        if (stat(file, &st))
                die_errno(_("Could not stat '%s'"), file);
        if (!st.st_size)
                die(_("Empty patch. Aborted."));
  
 -      memset(&child, 0, sizeof(child));
        child.git_cmd = 1;
        child.argv = apply_argv;
        if (run_command(&child))
@@@ -285,7 -285,7 +286,7 @@@ static int add_files(struct dir_struct 
                for (i = 0; i < dir->ignored_nr; i++)
                        fprintf(stderr, "%s\n", dir->ignored[i]->name);
                fprintf(stderr, _("Use -f if you really want to add them.\n"));
 -              die(_("no files added"));
 +              exit_status = 1;
        }
  
        for (i = 0; i < dir->nr; i++)
  int cmd_add(int argc, const char **argv, const char *prefix)
  {
        int exit_status = 0;
 -      int newfd;
        struct pathspec pathspec;
        struct dir_struct dir;
        int flags;
        add_new_files = !take_worktree_changes && !refresh_only;
        require_pathspec = !take_worktree_changes;
  
 -      newfd = hold_locked_index(&lock_file, 1);
 +      hold_locked_index(&lock_file, 1);
  
        flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
                 (show_only ? ADD_CACHE_PRETEND : 0) |
  
  finish:
        if (active_cache_changed) {
 -              if (write_cache(newfd, active_cache, active_nr) ||
 -                  commit_locked_index(&lock_file))
 +              if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                        die(_("Unable to write new index file"));
        }