Merge branch 'bp/commit-p-editor' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2014 19:07:06 +0000 (12:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2014 19:07:06 +0000 (12:07 -0700)
* bp/commit-p-editor:
run-command: mark run_hook_with_custom_index as deprecated
merge hook tests: fix and update tests
merge: fix GIT_EDITOR override for commit hook
commit: fix patch hunk editing with "commit -p -m"
test patch hunk editing with "commit -p -m"
merge hook tests: use 'test_must_fail' instead of '!'
merge hook tests: fix missing '&&' in test

1  2 
builtin/checkout.c
builtin/commit.c
commit.h
diff --combined builtin/checkout.c
index ada51fa70ff59b10fd79168a4377d923638591e9,624bfbad7c76dea54ce90e62f0717157f622e2e5..1b86d9c868c35c7f0ad3f4b39f9d225c8365c77c
@@@ -53,10 -53,10 +53,10 @@@ struct checkout_opts 
  static int post_checkout_hook(struct commit *old, struct commit *new,
                              int changed)
  {
-       return run_hook(NULL, "post-checkout",
-                       sha1_to_hex(old ? old->object.sha1 : null_sha1),
-                       sha1_to_hex(new ? new->object.sha1 : null_sha1),
-                       changed ? "1" : "0", NULL);
+       return run_hook_le(NULL, "post-checkout",
+                          sha1_to_hex(old ? old->object.sha1 : null_sha1),
+                          sha1_to_hex(new ? new->object.sha1 : null_sha1),
+                          changed ? "1" : "0", NULL);
        /* "new" can be NULL when checking out from the index before
           a commit exists. */
  
@@@ -297,7 -297,8 +297,7 @@@ static int checkout_paths(const struct 
                 * match_pathspec() for _all_ entries when
                 * opts->source_tree != NULL.
                 */
 -              if (match_pathspec_depth(&opts->pathspec, ce->name, ce_namelen(ce),
 -                                 0, ps_matched))
 +              if (ce_path_match(ce, &opts->pathspec, ps_matched))
                        ce->ce_flags |= CE_MATCHED;
        }
  
diff --combined builtin/commit.c
index 26b2986abe679b594798748b4776917050b1bd4d,baf1fc0fff2b1d910eb470797f7605a6a904bd60..6a60f668b28d1d27b4cb184a24f5b7e63af88f0b
@@@ -234,7 -234,7 +234,7 @@@ static int list_paths(struct string_lis
  
                if (ce->ce_flags & CE_UPDATE)
                        continue;
 -              if (!match_pathspec_depth(pattern, ce->name, ce_namelen(ce), 0, m))
 +              if (!ce_path_match(ce, pattern, m))
                        continue;
                item = string_list_insert(list, ce->name);
                if (ce_skip_worktree(ce))
@@@ -612,7 -612,7 +612,7 @@@ static int prepare_to_commit(const cha
        /* This checks and barfs if author is badly specified */
        determine_author_info(author_ident);
  
-       if (!no_verify && run_hook(index_file, "pre-commit", NULL))
+       if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", NULL))
                return 0;
  
        if (squash_message) {
                return 0;
        }
  
-       if (run_hook(index_file, "prepare-commit-msg",
-                    git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
+       if (run_commit_hook(use_editor, index_file, "prepare-commit-msg",
+                           git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
                return 0;
  
        if (use_editor) {
        }
  
        if (!no_verify &&
-           run_hook(index_file, "commit-msg", git_path(commit_editmsg), NULL)) {
+           run_commit_hook(use_editor, index_file, "commit-msg", git_path(commit_editmsg), NULL)) {
                return 0;
        }
  
@@@ -1067,8 -1067,6 +1067,6 @@@ static int parse_and_validate_options(i
                use_editor = 0;
        if (0 <= edit_flag)
                use_editor = edit_flag;
-       if (!use_editor)
-               setenv("GIT_EDITOR", ":", 1);
  
        /* Sanity check options */
        if (amend && !current_head)
@@@ -1445,6 -1443,29 +1443,29 @@@ static int run_rewrite_hook(const unsig
        return finish_command(&proc);
  }
  
+ int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...)
+ {
+       const char *hook_env[3] =  { NULL };
+       char index[PATH_MAX];
+       va_list args;
+       int ret;
+       snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
+       hook_env[0] = index;
+       /*
+        * Let the hook know that no editor will be launched.
+        */
+       if (!editor_is_used)
+               hook_env[1] = "GIT_EDITOR=:";
+       va_start(args, name);
+       ret = run_hook_ve(hook_env, name, args);
+       va_end(args);
+       return ret;
+ }
  int cmd_commit(int argc, const char **argv, const char *prefix)
  {
        static struct wt_status s;
                     "not exceeded, and then \"git reset HEAD\" to recover."));
  
        rerere(0);
-       run_hook(get_index_file(), "post-commit", NULL);
+       run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
        if (amend && !no_post_rewrite) {
                struct notes_rewrite_cfg *cfg;
                cfg = init_copy_notes_for_rewrite("amend");
diff --combined commit.h
index 55631f191f2a01276e8a16192117fb3cf25bc958,8d97a5caa3bd3ff5686f68998102527a3876bc4f..a9f177ba488a7002409eb2cdee1f7e9c3673529f
+++ b/commit.h
@@@ -209,7 -209,7 +209,7 @@@ extern int write_shallow_commits(struc
  extern void setup_alternate_shallow(struct lock_file *shallow_lock,
                                    const char **alternate_shallow_file,
                                    const struct sha1_array *extra);
 -extern char *setup_temporary_shallow(const struct sha1_array *extra);
 +extern const char *setup_temporary_shallow(const struct sha1_array *extra);
  extern void advertise_shallow_grafts(int);
  
  struct shallow_info {
@@@ -304,4 -304,7 +304,7 @@@ extern void check_commit_signature(cons
  
  int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused);
  
+ LAST_ARG_MUST_BE_NULL
+ extern int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...);
  #endif /* COMMIT_H */