Skip to content

Commit 2d24690

Browse files
committed
Add testcase
1 parent 4c462bb commit 2d24690

14 files changed

+66
-0
lines changed

tests/diff/rename.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ void test_diff_rename__cleanup(void)
2121
#define RENAME_MODIFICATION_COMMIT "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13"
2222
#define REWRITE_DELETE_COMMIT "84d8efa38af7ace2b302de0adbda16b1f1cd2e1b"
2323
#define DELETE_RENAME_COMMIT "be053a189b0bbde545e0a3f59ce00b46ad29ce0d"
24+
#define BREAK_REWRITE_BASE_COMMIT "db98035f715427eef1f5e17f03e1801c05301e9e"
25+
#define BREAK_REWRITE_COMMIT "7e7bfb88ba9bc65fd700fee1819cf1c317aafa56"
2426

2527
/*
2628
* Renames repo has:
@@ -1977,3 +1979,56 @@ void test_diff_rename__delete_and_rename(void)
19771979
git_tree_free(old_tree);
19781980
git_tree_free(new_tree);
19791981
}
1982+
1983+
/*
1984+
* The break_rewrite branch contains a testcase reduced from
1985+
* a real-world scenario, rather than being "constructed" like
1986+
* the above tests seem to be. There are two commits layered
1987+
* on top of the repo's initial commit; the base commit which
1988+
* clears out the files from the initial commit and installs
1989+
* four files. And then there's the modification commit which
1990+
* mutates the files in such a way as to trigger the bug in
1991+
* libgit2.
1992+
* commit db98035f715427eef1f5e17f03e1801c05301e9e
1993+
* serving.txt (deleted)
1994+
* sevencities.txt (deleted)
1995+
* AAA (313 lines)
1996+
* BBB (314 lines)
1997+
* CCC (704 lines)
1998+
* DDD (314 lines, identical to BBB)
1999+
* commit 7e7bfb88ba9bc65fd700fee1819cf1c317aafa56
2000+
* This deletes CCC and makes slight modifications
2001+
* to AAA, BBB, and DDD. The find_best_matches loop
2002+
* for git_diff_find_similar computes the following:
2003+
* CCC moved to AAA (similarity 91)
2004+
* CCC copied to AAA (similarity 91)
2005+
* DDD moved to BBB (similarity 52)
2006+
* CCC copied to BBB (similarity 90)
2007+
* BBB moved to DDD (similarity 52)
2008+
* CCC copied to DDD (similarity 90)
2009+
* The code to rewrite the diffs by resolving these
2010+
* copies/renames would resolve the BBB <-> DDD moves
2011+
* but then still leave BBB as a rename target for
2012+
* the deleted file CCC. Since the split flag on BBB
2013+
* was cleared, this would trigger an error.
2014+
*/
2015+
void test_diff_rename__break_rewrite(void)
2016+
{
2017+
const char *old_sha = BREAK_REWRITE_BASE_COMMIT;
2018+
const char *new_sha = BREAK_REWRITE_COMMIT;
2019+
git_tree *old_tree, *new_tree;
2020+
git_diff *diff;
2021+
git_diff_find_options find_opts = GIT_DIFF_FIND_OPTIONS_INIT;
2022+
2023+
old_tree = resolve_commit_oid_to_tree(g_repo, old_sha);
2024+
new_tree = resolve_commit_oid_to_tree(g_repo, new_sha);
2025+
2026+
find_opts.flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES | GIT_DIFF_BREAK_REWRITES | GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY;
2027+
2028+
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, old_tree, new_tree, NULL));
2029+
cl_git_pass(git_diff_find_similar(diff, &find_opts));
2030+
2031+
git_diff_free(diff);
2032+
git_tree_free(old_tree);
2033+
git_tree_free(new_tree);
2034+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13
33 Bytes
Binary file not shown.

tests/resources/renames/.gitted/logs/HEAD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 2bc7f351d20b53f1c72c16c4b036e491c478c49a Russell Belfer <rb@github.com> 1351024817 -0700 commit: copy and rename with no change
33
2bc7f351d20b53f1c72c16c4b036e491c478c49a 1c068dee5790ef1580cfc4cd670915b48d790084 Russell Belfer <rb@github.com> 1361485758 -0800 commit: rewrites, copies with changes, etc.
44
1c068dee5790ef1580cfc4cd670915b48d790084 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13 Russell Belfer <rb@github.com> 1361486360 -0800 commit: more renames and smallish modifications
5+
19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 Kartikaya Gupta <kats@pancake.staktrace.com> 1618486966 -0400 checkout: moving from master to break_rewrite
6+
31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 db98035f715427eef1f5e17f03e1801c05301e9e Kartikaya Gupta <kats@pancake.staktrace.com> 1618487039 -0400 commit: This test needs to start with a minimum of four files
7+
db98035f715427eef1f5e17f03e1801c05301e9e 7e7bfb88ba9bc65fd700fee1819cf1c317aafa56 Kartikaya Gupta <kats@pancake.staktrace.com> 1618487097 -0400 commit: Copy/modify files around
8+
7e7bfb88ba9bc65fd700fee1819cf1c317aafa56 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13 Kartikaya Gupta <kats@pancake.staktrace.com> 1618487105 -0400 checkout: moving from break_rewrite to master
9+
19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13 19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13 Kartikaya Gupta <kats@pancake.staktrace.com> 1618487271 -0400 reset: moving to HEAD
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��Kn�0��)����)�"e1�9Ec�
2+
b��4 n�0�WR�^��2)؎>���'�V��L�� ��܀׎<�Dv!yg��MV�q��P"o�H��b�TJH�C�^ �W<��4���86e��Y����̳�v�Yg��|u�|��G�D�h.z�Uy�c~�vޗ:N�2�dn�XG� �T�
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x+)JMU042a040031Qpttd83���я�fӮ�-�[y�����Pi'''���]�V�*�
2+
�J8���ĉ�nPiggg�כ���U=ᩫ���vR%b��� Pi���:6�
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)