Skip to content

Commit 5c8c0a0

Browse files
committed
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
2 parents b75ba9b + 4627bc7 commit 5c8c0a0

File tree

6 files changed

+432
-265
lines changed

6 files changed

+432
-265
lines changed

builtin/commit.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,28 +1463,6 @@ static int git_commit_config(const char *k, const char *v, void *cb)
14631463
return git_status_config(k, v, s);
14641464
}
14651465

1466-
int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...)
1467-
{
1468-
struct argv_array hook_env = ARGV_ARRAY_INIT;
1469-
va_list args;
1470-
int ret;
1471-
1472-
argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
1473-
1474-
/*
1475-
* Let the hook know that no editor will be launched.
1476-
*/
1477-
if (!editor_is_used)
1478-
argv_array_push(&hook_env, "GIT_EDITOR=:");
1479-
1480-
va_start(args, name);
1481-
ret = run_hook_ve(hook_env.argv,name, args);
1482-
va_end(args);
1483-
argv_array_clear(&hook_env);
1484-
1485-
return ret;
1486-
}
1487-
14881466
int cmd_commit(int argc, const char **argv, const char *prefix)
14891467
{
14901468
const char *argv_gc_auto[] = {"gc", "--auto", NULL};

commit.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "advice.h"
2020
#include "refs.h"
2121
#include "commit-reach.h"
22+
#include "run-command.h"
2223

2324
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
2425

@@ -1581,3 +1582,26 @@ size_t ignore_non_trailer(const char *buf, size_t len)
15811582
}
15821583
return boc ? len - boc : len - cutoff;
15831584
}
1585+
1586+
int run_commit_hook(int editor_is_used, const char *index_file,
1587+
const char *name, ...)
1588+
{
1589+
struct argv_array hook_env = ARGV_ARRAY_INIT;
1590+
va_list args;
1591+
int ret;
1592+
1593+
argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
1594+
1595+
/*
1596+
* Let the hook know that no editor will be launched.
1597+
*/
1598+
if (!editor_is_used)
1599+
argv_array_push(&hook_env, "GIT_EDITOR=:");
1600+
1601+
va_start(args, name);
1602+
ret = run_hook_ve(hook_env.argv,name, args);
1603+
va_end(args);
1604+
argv_array_clear(&hook_env);
1605+
1606+
return ret;
1607+
}

sequencer.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,25 +1126,22 @@ static int run_prepare_commit_msg_hook(struct repository *r,
11261126
struct strbuf *msg,
11271127
const char *commit)
11281128
{
1129-
struct argv_array hook_env = ARGV_ARRAY_INIT;
1130-
int ret;
1131-
const char *name;
1129+
int ret = 0;
1130+
const char *name, *arg1 = NULL, *arg2 = NULL;
11321131

11331132
name = git_path_commit_editmsg();
11341133
if (write_message(msg->buf, msg->len, name, 0))
11351134
return -1;
11361135

1137-
argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", r->index_file);
1138-
argv_array_push(&hook_env, "GIT_EDITOR=:");
1139-
if (commit)
1140-
ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name,
1141-
"commit", commit, NULL);
1142-
else
1143-
ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name,
1144-
"message", NULL);
1145-
if (ret)
1136+
if (commit) {
1137+
arg1 = "commit";
1138+
arg2 = commit;
1139+
} else {
1140+
arg1 = "message";
1141+
}
1142+
if (run_commit_hook(0, r->index_file, "prepare-commit-msg", name,
1143+
arg1, arg2, NULL))
11461144
ret = error(_("'prepare-commit-msg' hook failed"));
1147-
argv_array_clear(&hook_env);
11481145

11491146
return ret;
11501147
}
@@ -1403,6 +1400,7 @@ static int try_to_commit(struct repository *r,
14031400
goto out;
14041401
}
14051402

1403+
run_commit_hook(0, r->index_file, "post-commit", NULL);
14061404
if (flags & AMEND_MSG)
14071405
commit_post_rewrite(r, current_head, oid);
14081406

sequencer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,10 @@ void print_commit_summary(struct repository *repo,
202202

203203
int read_author_script(const char *path, char **name, char **email, char **date,
204204
int allow_missing);
205-
#endif
206-
207205
void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
208206
int write_basic_state(struct replay_opts *opts, const char *head_name,
209207
struct commit *onto, const char *orig_head);
210208
void sequencer_post_commit_cleanup(struct repository *r, int verbose);
211209
int sequencer_get_last_command(struct repository* r,
212210
enum replay_action *action);
211+
#endif /* SEQUENCER_H */

t/lib-rebase.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,31 @@ make_empty () {
119119
git commit --allow-empty -m "$1" &&
120120
git tag "$1"
121121
}
122+
123+
# Call this (inside test_expect_success) at the end of a test file to
124+
# check that no tests have changed editor related environment
125+
# variables or config settings
126+
test_editor_unchanged () {
127+
# We're only interested in exported variables hence 'sh -c'
128+
sh -c 'cat >actual <<-EOF
129+
EDITOR=$EDITOR
130+
FAKE_COMMIT_AMEND=$FAKE_COMMIT_AMEND
131+
FAKE_COMMIT_MESSAGE=$FAKE_COMMIT_MESSAGE
132+
FAKE_LINES=$FAKE_LINES
133+
GIT_EDITOR=$GIT_EDITOR
134+
GIT_SEQUENCE_EDITOR=$GIT_SEQUENCE_EDITOR
135+
core.editor=$(git config core.editor)
136+
sequence.editor=$(git config sequence.editor)
137+
EOF'
138+
cat >expect <<-\EOF
139+
EDITOR=:
140+
FAKE_COMMIT_AMEND=
141+
FAKE_COMMIT_MESSAGE=
142+
FAKE_LINES=
143+
GIT_EDITOR=
144+
GIT_SEQUENCE_EDITOR=
145+
core.editor=
146+
sequence.editor=
147+
EOF
148+
test_cmp expect actual
149+
}

0 commit comments

Comments
 (0)