When writing the todo script for --rebase-merges, we try to find a label for certain commits. If the label ends up being a valid object ID, such as when we merge a detached commit, we want to rewrite it so it is no longer a valid object ID. However, the code path that does this checks for its length to be equivalent to GIT_SHA1_RAWSZ, which isn't correct, since what we are reading is a hex object ID. Instead, check for the length being equivalent to that of a hex object ID. Use the_hash_algo so this code works regardless of the hash size. Signed-off-by: brian m. carlson <sandals@xxxxxxxxxxxxxxxxxxxx> --- sequencer.c | 2 +- t/t3430-rebase-merges.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 1ce63261a3..75ed86a94e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3636,7 +3636,7 @@ static const char *label_oid(struct object_id *oid, const char *label, p[i] = save; } } - } else if (((len = strlen(label)) == GIT_SHA1_RAWSZ && + } else if (((len = strlen(label)) == the_hash_algo->hexsz && !get_oid_hex(label, &dummy)) || (len == 1 && *label == '#') || hashmap_get_from_hash(&state->labels, diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 3d4dfdf7be..9fc4648ff8 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -241,4 +241,20 @@ test_expect_success 'refuse to merge ancestors of HEAD' ' test_cmp_rev HEAD $before ' +test_expect_success 'labels that are object IDs are rewritten' ' + git checkout -b third B && + test_commit I && + third=$(git rev-parse HEAD) && + git checkout -b labels master && + git merge --no-commit third && + test_tick && + git commit -m "Merge commit '\''$third'\'' into labels" && + echo noop >script-from-scratch && + test_config sequence.editor \""$PWD"/replace-editor.sh\" && + test_tick && + git rebase -i -r A && + grep "^label $third-" .git/ORIGINAL-TODO && + ! grep "^label $third$" .git/ORIGINAL-TODO +' + test_done