Skip to content

Commit ab0e1d1

Browse files
pks-tgitster
authored andcommitted
builtin/history: check for merges before asking for user input
The replay infrastructure is not yet capable of replaying merge commits. Unfortunately, we only notice that we're about to replay merges after we have already asked the user for input, so any commit message that the user may have written will be discarded in that case. Fix this by checking whether the revwalk contains merge commits before we ask for user input. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6741376 commit ab0e1d1

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

builtin/history.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,42 @@ static int parse_ref_action(const struct option *opt, const char *value, int uns
177177
return 0;
178178
}
179179

180+
static int revwalk_contains_merges(struct repository *repo,
181+
const struct strvec *revwalk_args)
182+
{
183+
struct strvec args = STRVEC_INIT;
184+
struct rev_info revs;
185+
int ret;
186+
187+
for (size_t i = 0; i < revwalk_args->nr; i++)
188+
strvec_push(&args, revwalk_args->v[i]);
189+
strvec_push(&args, "--min-parents=2");
190+
191+
repo_init_revisions(repo, &revs, NULL);
192+
193+
setup_revisions_from_strvec(&args, &revs, NULL);
194+
if (args.nr != 1)
195+
BUG("revisions were set up with invalid argument");
196+
197+
if (prepare_revision_walk(&revs) < 0) {
198+
ret = error(_("error preparing revisions"));
199+
goto out;
200+
}
201+
202+
if (get_revision(&revs)) {
203+
ret = error(_("replaying merge commits is not supported yet!"));
204+
goto out;
205+
}
206+
207+
reset_revision_walk();
208+
ret = 0;
209+
210+
out:
211+
release_revisions(&revs);
212+
strvec_clear(&args);
213+
return ret;
214+
}
215+
180216
static int setup_revwalk(struct repository *repo,
181217
enum ref_action action,
182218
struct commit *original,
@@ -236,6 +272,10 @@ static int setup_revwalk(struct repository *repo,
236272
strvec_push(&args, "HEAD");
237273
}
238274

275+
ret = revwalk_contains_merges(repo, &args);
276+
if (ret < 0)
277+
goto out;
278+
239279
setup_revisions_from_strvec(&args, revs, NULL);
240280
if (args.nr != 1)
241281
BUG("revisions were set up with invalid argument");

t/t3451-history-reword.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ test_expect_success 'can reword a merge commit' '
203203
204204
# It is not possible to replay merge commits embedded in the
205205
# history (yet).
206-
test_must_fail git history reword HEAD~ 2>err &&
206+
test_must_fail git -c core.editor=false history reword HEAD~ 2>err &&
207207
test_grep "replaying merge commits is not supported yet" err &&
208208
209209
# But it is possible to reword a merge commit directly.

0 commit comments

Comments
 (0)