зеркало из https://github.com/microsoft/git.git
Merge branch 'pw/post-commit-from-sequencer'
"rebase -i" ceased to run post-commit hook by mistake in an earlier update, which has been corrected. * pw/post-commit-from-sequencer: sequencer: run post-commit hook move run_commit_hook() to libgit and use it there sequencer.h fix placement of #endif t3404: remove uneeded calls to set_fake_editor t3404: set $EDITOR in subshell t3404: remove unnecessary subshell
This commit is contained in:
Коммит
5c8c0a0d78
|
@ -1463,28 +1463,6 @@ static int git_commit_config(const char *k, const char *v, void *cb)
|
|||
return git_status_config(k, v, s);
|
||||
}
|
||||
|
||||
int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...)
|
||||
{
|
||||
struct argv_array hook_env = ARGV_ARRAY_INIT;
|
||||
va_list args;
|
||||
int ret;
|
||||
|
||||
argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
|
||||
|
||||
/*
|
||||
* Let the hook know that no editor will be launched.
|
||||
*/
|
||||
if (!editor_is_used)
|
||||
argv_array_push(&hook_env, "GIT_EDITOR=:");
|
||||
|
||||
va_start(args, name);
|
||||
ret = run_hook_ve(hook_env.argv,name, args);
|
||||
va_end(args);
|
||||
argv_array_clear(&hook_env);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int cmd_commit(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
const char *argv_gc_auto[] = {"gc", "--auto", NULL};
|
||||
|
|
24
commit.c
24
commit.c
|
@ -19,6 +19,7 @@
|
|||
#include "advice.h"
|
||||
#include "refs.h"
|
||||
#include "commit-reach.h"
|
||||
#include "run-command.h"
|
||||
|
||||
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
|
||||
|
||||
|
@ -1581,3 +1582,26 @@ size_t ignore_non_trailer(const char *buf, size_t len)
|
|||
}
|
||||
return boc ? len - boc : len - cutoff;
|
||||
}
|
||||
|
||||
int run_commit_hook(int editor_is_used, const char *index_file,
|
||||
const char *name, ...)
|
||||
{
|
||||
struct argv_array hook_env = ARGV_ARRAY_INIT;
|
||||
va_list args;
|
||||
int ret;
|
||||
|
||||
argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
|
||||
|
||||
/*
|
||||
* Let the hook know that no editor will be launched.
|
||||
*/
|
||||
if (!editor_is_used)
|
||||
argv_array_push(&hook_env, "GIT_EDITOR=:");
|
||||
|
||||
va_start(args, name);
|
||||
ret = run_hook_ve(hook_env.argv,name, args);
|
||||
va_end(args);
|
||||
argv_array_clear(&hook_env);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
24
sequencer.c
24
sequencer.c
|
@ -1126,25 +1126,22 @@ static int run_prepare_commit_msg_hook(struct repository *r,
|
|||
struct strbuf *msg,
|
||||
const char *commit)
|
||||
{
|
||||
struct argv_array hook_env = ARGV_ARRAY_INIT;
|
||||
int ret;
|
||||
const char *name;
|
||||
int ret = 0;
|
||||
const char *name, *arg1 = NULL, *arg2 = NULL;
|
||||
|
||||
name = git_path_commit_editmsg();
|
||||
if (write_message(msg->buf, msg->len, name, 0))
|
||||
return -1;
|
||||
|
||||
argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", r->index_file);
|
||||
argv_array_push(&hook_env, "GIT_EDITOR=:");
|
||||
if (commit)
|
||||
ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name,
|
||||
"commit", commit, NULL);
|
||||
else
|
||||
ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name,
|
||||
"message", NULL);
|
||||
if (ret)
|
||||
if (commit) {
|
||||
arg1 = "commit";
|
||||
arg2 = commit;
|
||||
} else {
|
||||
arg1 = "message";
|
||||
}
|
||||
if (run_commit_hook(0, r->index_file, "prepare-commit-msg", name,
|
||||
arg1, arg2, NULL))
|
||||
ret = error(_("'prepare-commit-msg' hook failed"));
|
||||
argv_array_clear(&hook_env);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -1403,6 +1400,7 @@ static int try_to_commit(struct repository *r,
|
|||
goto out;
|
||||
}
|
||||
|
||||
run_commit_hook(0, r->index_file, "post-commit", NULL);
|
||||
if (flags & AMEND_MSG)
|
||||
commit_post_rewrite(r, current_head, oid);
|
||||
|
||||
|
|
|
@ -202,11 +202,10 @@ void print_commit_summary(struct repository *repo,
|
|||
|
||||
int read_author_script(const char *path, char **name, char **email, char **date,
|
||||
int allow_missing);
|
||||
#endif
|
||||
|
||||
void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
|
||||
int write_basic_state(struct replay_opts *opts, const char *head_name,
|
||||
struct commit *onto, const char *orig_head);
|
||||
void sequencer_post_commit_cleanup(struct repository *r, int verbose);
|
||||
int sequencer_get_last_command(struct repository* r,
|
||||
enum replay_action *action);
|
||||
#endif /* SEQUENCER_H */
|
||||
|
|
|
@ -119,3 +119,31 @@ make_empty () {
|
|||
git commit --allow-empty -m "$1" &&
|
||||
git tag "$1"
|
||||
}
|
||||
|
||||
# Call this (inside test_expect_success) at the end of a test file to
|
||||
# check that no tests have changed editor related environment
|
||||
# variables or config settings
|
||||
test_editor_unchanged () {
|
||||
# We're only interested in exported variables hence 'sh -c'
|
||||
sh -c 'cat >actual <<-EOF
|
||||
EDITOR=$EDITOR
|
||||
FAKE_COMMIT_AMEND=$FAKE_COMMIT_AMEND
|
||||
FAKE_COMMIT_MESSAGE=$FAKE_COMMIT_MESSAGE
|
||||
FAKE_LINES=$FAKE_LINES
|
||||
GIT_EDITOR=$GIT_EDITOR
|
||||
GIT_SEQUENCE_EDITOR=$GIT_SEQUENCE_EDITOR
|
||||
core.editor=$(git config core.editor)
|
||||
sequence.editor=$(git config sequence.editor)
|
||||
EOF'
|
||||
cat >expect <<-\EOF
|
||||
EDITOR=:
|
||||
FAKE_COMMIT_AMEND=
|
||||
FAKE_COMMIT_MESSAGE=
|
||||
FAKE_LINES=
|
||||
GIT_EDITOR=
|
||||
GIT_SEQUENCE_EDITOR=
|
||||
core.editor=
|
||||
sequence.editor=
|
||||
EOF
|
||||
test_cmp expect actual
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче