Skip to content

Commit 88f905e

Browse files
tgummerergitster
authored andcommitted
rerere: recalculate conflict ID when unresolved conflict is committed
Currently when a user doesn't resolve a conflict, commits the results, and does an operation which creates another conflict, rerere will use the ID of the previously unresolved conflict for the new conflict. This is because the conflict is kept in the MERGE_RR file, which 'rerere' reads every time it is invoked. After the new conflict is solved, rerere will record the resolution with the ID of the old conflict. So in order to replay the conflict, both merges would have to be re-done, instead of just the last one, in order for rerere to be able to automatically resolve the conflict. Instead of that, assign a new conflict ID if there are still conflicts in a file and the file had conflicts at a previous step. This ID matches the conflict we actually resolved at the corresponding step. Note that there are no backwards compatibility worries here, as rerere would have failed to even normalize the conflict before this patch series. Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71a30ee commit 88f905e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

rerere.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,20 +815,19 @@ static int do_plain_rerere(struct string_list *rr, int fd)
815815
struct rerere_id *id;
816816
unsigned char sha1[20];
817817
const char *path = conflict.items[i].string;
818-
int ret, has_string;
818+
int ret;
819819

820820
/*
821821
* Ask handle_file() to scan and assign a
822822
* conflict ID. No need to write anything out
823823
* yet.
824824
*/
825825
ret = handle_file(path, sha1, NULL);
826-
has_string = string_list_has_string(rr, path);
827-
if (ret < 0 && has_string) {
826+
if (ret != 0 && string_list_has_string(rr, path)) {
828827
remove_variant(string_list_lookup(rr, path)->util);
829828
string_list_remove(rr, path, 1);
830829
}
831-
if (ret < 1 || has_string)
830+
if (ret < 1)
832831
continue;
833832

834833
id = new_rerere_id(sha1);

t/t4200-rerere.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,13 @@ test_expect_success 'rerere with inner conflict markers' '
636636
git commit -q -m "will solve conflicts later" &&
637637
test_must_fail git merge A &&
638638
cat test >actual &&
639+
test_cmp expect actual &&
640+
641+
git add test &&
642+
git commit -m "rerere solved conflict" &&
643+
git reset --hard HEAD~ &&
644+
test_must_fail git merge A &&
645+
cat test >actual &&
639646
test_cmp expect actual
640647
'
641648

0 commit comments

Comments
 (0)