filter-repo: add testcases dealing with topology changes

Pruning of commits which become empty can result in a variety of
topology changes: a merge may have lost all its ancestors corresponding
to one of (or more) of its parents, a merge may end up merging a commit
with itself, or a merge may end up merging a commit with its own
ancestor.  Merging a commit with itself makes no sense, so we'd rather
prune down to one parent and hopefully prune the merge commit, but we do
need to worry about whether the are changes in the commit and whether
the original merge commit also merged something with itself.  We have
similar cases for dealing with a merge of some commit with its own
ancestor: if the original topology did the same, or the merge commit has
additional file changes, then we cannot remove the commit.  But,
otherwise, the commit can be pruned.

Add testcases covering the variety of changes that can occur to make
sure we get them right.

Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
Elijah Newren 2019-02-23 08:15:07 -08:00
parent 697b9256f5
commit 5ba62ba4e8
5 changed files with 970 additions and 0 deletions

View File

@ -39,5 +39,8 @@ filter_testcase basic basic-numbers --invert-paths --path-regex 'f.*e.*e'
filter_testcase basic basic-mailmap --mailmap ../t9390/sample-mailmap
filter_testcase basic basic-replace --replace-text ../t9390/sample-replace
filter_testcase empty empty-keepme --path keepme
filter_testcase degenerate degenerate-keepme --path moduleA/keepme
filter_testcase degenerate degenerate-moduleA --path moduleA
filter_testcase degenerate degenerate-globme --path-glob *me
test_done

402
t/t9390/degenerate Normal file
View File

@ -0,0 +1,402 @@
feature done
# Simple repo with only three files, with a bunch of cases of dealing with
# topology changes possibly causing merge commits to need to be pruned.
#
# As with case1, the original-oid directives are very fake, but if an error
# is hit that shows one of these, it makes it really easy to know where it
# came from.
#
# Expressed with shorthand, log history in the format
# Commit Name(Parent(s)): files changed
# for this case looks like the following:
# W(V): moduleA/keepme
# V(U,U): moduleB/nukeme
# U(T): moduleA/sometimes
# T(S): moduleA/keepme
# S(R,R): moduleA/sometimes
# R(R): moduleB/nukeme
# Q(P): moduleA/keepme
# P(N,M): moduleA/sometimes
# O(M,N): moduleA/sometimes
# N(C): moduleB/nukeme
# M(L): moduleB/nukeme
# L(K): moduleA/keepme
# K(J): moduleB/nukeme
# J(D,H): moduleA/sometimes
# I(H,D): moduleA/sometimes # backwards-ish merge
# H(G): moduleB/nukeme
# G(F): moduleA/keepme
# F(D): moduleB/nukeme
# D(B,C): moduleA/sometimes
# C(A): moduleB/nukeme
# B(A): moduleB/nukeme
# A(): moduleA/keepme
#
# This involved case is intended to test the following:
# * Merge becoming non-merge due to both parents becoming same commit
# * Two sub-cases: it has changes of its own, or it doesn't
# * Merge becoming merge of commit with its own ancestor
# * Two cases: and it has changes, and it doesn't have changes
# * Two cases: first parent is the ancestor, second parent is the ancestor
# * Merge starting as merge of commit with its own ancestor
# * Two cases: has changes, doesn't have changes
# * Two cases: first parent, or second parent
blob
mark :1
original-oid 0000000000000000000000000000000000000001
data 10
keepme v1
blob
mark :2
original-oid 0000000000000000000000000000000000000002
data 10
nukeme v1
blob
mark :3
original-oid 0000000000000000000000000000000000000003
data 10
nukeme v2
blob
mark :4
original-oid 0000000000000000000000000000000000000004
data 13
sometimes v1
blob
mark :5
original-oid 0000000000000000000000000000000000000005
data 10
nukeme v3
blob
mark :6
original-oid 0000000000000000000000000000000000000006
data 10
keepme v2
blob
mark :7
original-oid 0000000000000000000000000000000000000007
data 10
nukem4 v4
blob
mark :8
original-oid 0000000000000000000000000000000000000008
data 13
sometimes v2
blob
mark :9
original-oid 0000000000000000000000000000000000000009
data 13
sometimes v3
blob
mark :10
original-oid 000000000000000000000000000000000000000A
data 10
nukeme v4
blob
mark :11
original-oid 000000000000000000000000000000000000000B
data 10
keepme v3
blob
mark :12
original-oid 000000000000000000000000000000000000000C
data 10
nukeme v5
blob
mark :13
original-oid 000000000000000000000000000000000000000D
data 10
nukeme v6
blob
mark :14
original-oid 000000000000000000000000000000000000000E
data 13
sometimes v4
blob
mark :15
original-oid 000000000000000000000000000000000000000F
data 13
sometimes v5
blob
mark :16
original-oid 0000000000000000000000000000000000000010
data 10
keepme v4
blob
mark :17
original-oid 0000000000000000000000000000000000000011
data 10
nukeme v7
blob
mark :18
original-oid 0000000000000000000000000000000000000012
data 13
sometimes v6
blob
mark :19
original-oid 0000000000000000000000000000000000000013
data 10
keepme v5
blob
mark :20
original-oid 0000000000000000000000000000000000000014
data 13
sometimes v7
blob
mark :21
original-oid 0000000000000000000000000000000000000015
data 10
nukeme v8
blob
mark :22
original-oid 0000000000000000000000000000000000000016
data 10
keepme v6
commit refs/heads/master
mark :26
original-oid 0000000000000000000000000000000000000020
author Full Name <user@organization.tld> 2000000000 +0100
committer Full Name <user@organization.tld> 2000000000 +0100
data 2
A
M 100644 :1 moduleA/keepme
commit refs/heads/master
mark :27
original-oid 0000000000000000000000000000000000000021
author Full Name <user@organization.tld> 2000010000 +0100
committer Full Name <user@organization.tld> 2000010000 +0100
data 2
B
from :26
M 100644 :2 moduleB/nukeme
commit refs/heads/master
mark :28
original-oid 0000000000000000000000000000000000000022
author Full Name <user@organization.tld> 2000020000 +0100
committer Full Name <user@organization.tld> 2000020000 +0100
data 2
C
from :26
M 100644 :3 moduleB/nukeme
commit refs/heads/master
mark :29
original-oid 0000000000000000000000000000000000000023
author Full Name <user@organization.tld> 2000030000 +0100
committer Full Name <user@organization.tld> 2000030000 +0100
data 29
D: Merge commit 'C' into 'B'
from :27
merge :28
M 100644 :4 moduleA/sometimes
commit refs/heads/master
mark :30
original-oid 0000000000000000000000000000000000000024
author Full Name <user@organization.tld> 2000040000 +0100
committer Full Name <user@organization.tld> 2000040000 +0100
data 2
F
from :29
M 100644 :5 moduleB/nukeme
commit refs/heads/master
mark :31
original-oid 0000000000000000000000000000000000000025
author Full Name <user@organization.tld> 2000050000 +0100
committer Full Name <user@organization.tld> 2000050000 +0100
data 2
G
from :30
M 100644 :6 moduleA/keepme
commit refs/heads/master
mark :32
original-oid 0000000000000000000000000000000000000026
author Full Name <user@organization.tld> 2000060000 +0100
committer Full Name <user@organization.tld> 2000060000 +0100
data 2
H
from :31
M 100644 :7 moduleB/nukeme
commit refs/heads/branchI
mark :33
original-oid 0000000000000000000000000000000000000027
author Full Name <user@organization.tld> 2000070000 +0100
committer Full Name <user@organization.tld> 2000070000 +0100
data 29
I: Merge commit 'D' into 'H'
from :32
merge :29
M 100644 :8 moduleA/sometimes
commit refs/heads/master
mark :34
original-oid 0000000000000000000000000000000000000028
author Full Name <user@organization.tld> 2000080000 +0100
committer Full Name <user@organization.tld> 2000080000 +0100
data 29
J: Merge commit 'H' into 'D'
from :29
merge :32
M 100644 :9 moduleA/sometimes
commit refs/heads/master
mark :35
original-oid 0000000000000000000000000000000000000029
author Full Name <user@organization.tld> 2000090000 +0100
committer Full Name <user@organization.tld> 2000090000 +0100
data 2
K
from :34
M 100644 :10 moduleB/nukeme
commit refs/heads/master
mark :36
original-oid 000000000000000000000000000000000000002A
author Full Name <user@organization.tld> 2000092000 +0100
committer Full Name <user@organization.tld> 2000092000 +0100
data 2
L
from :35
M 100644 :11 moduleA/keepme
commit refs/heads/master
mark :37
original-oid 000000000000000000000000000000000000002B
author Full Name <user@organization.tld> 2000094000 +0100
committer Full Name <user@organization.tld> 2000094000 +0100
data 2
M
from :36
M 100644 :12 moduleB/nukeme
commit refs/heads/master
mark :38
original-oid 000000000000000000000000000000000000002C
author Full Name <user@organization.tld> 2000096000 +0100
committer Full Name <user@organization.tld> 2000096000 +0100
data 2
N
from :28
M 100644 :13 moduleB/nukeme
commit refs/heads/branchO
mark :39
original-oid 000000000000000000000000000000000000002D
author Full Name <user@organization.tld> 2000098000 +0100
committer Full Name <user@organization.tld> 2000098000 +0100
data 29
O: Merge commit 'N' into 'M'
from :37
merge :38
D moduleA/sometimes
commit refs/heads/master
mark :40
original-oid 000000000000000000000000000000000000002E
author Full Name <user@organization.tld> 2000099000 +0100
committer Full Name <user@organization.tld> 2000099000 +0100
data 29
P: Merge commit 'M' into 'N'
from :38
merge :37
M 100644 :15 moduleA/sometimes
commit refs/heads/master
mark :41
original-oid 0000000000000000000000000000000000000030
author Full Name <user@organization.tld> 3000000000 +0100
committer Full Name <user@organization.tld> 3000000000 +0100
data 2
Q
from :40
M 100644 :16 moduleA/keepme
commit refs/heads/master
mark :42
original-oid 0000000000000000000000000000000000000031
author Full Name <user@organization.tld> 3000010000 +0100
committer Full Name <user@organization.tld> 3000010000 +0100
data 2
R
from :41
M 100644 :17 moduleB/nukeme
commit refs/heads/master
mark :43
original-oid 0000000000000000000000000000000000000032
author Full Name <user@organization.tld> 3000020000 +0100
committer Full Name <user@organization.tld> 3000020000 +0100
data 29
S: Merge commit 'R' into 'R'
from :42
merge :42
M 100644 :18 moduleA/sometimes
commit refs/heads/master
mark :44
original-oid 0000000000000000000000000000000000000033
author Full Name <user@organization.tld> 3000030000 +0100
committer Full Name <user@organization.tld> 3000030000 +0100
data 2
T
from :43
M 100644 :19 moduleA/keepme
commit refs/heads/master
mark :45
original-oid 0000000000000000000000000000000000000034
author Full Name <user@organization.tld> 3000040000 +0100
committer Full Name <user@organization.tld> 3000040000 +0100
data 2
U
from :44
M 100644 :20 moduleA/sometimes
commit refs/heads/master
mark :46
original-oid 0000000000000000000000000000000000000035
author Full Name <user@organization.tld> 3000050000 +0100
committer Full Name <user@organization.tld> 3000050000 +0100
data 29
V: Merge commit 'U' into 'U'
from :45
merge :45
M 100644 :21 moduleB/nukeme
commit refs/heads/master
mark :47
original-oid 0000000000000000000000000000000000000036
author Full Name <user@organization.tld> 3000060000 +0100
committer Full Name <user@organization.tld> 3000060000 +0100
data 2
W
from :46
M 100644 :22 moduleA/keepme
done

267
t/t9390/degenerate-globme Normal file
View File

@ -0,0 +1,267 @@
feature done
blob
mark :1
data 10
keepme v1
reset refs/heads/master
commit refs/heads/master
mark :2
author Full Name <user@organization.tld> 2000000000 +0100
committer Full Name <user@organization.tld> 2000000000 +0100
data 2
A
M 100644 :1 moduleA/keepme
blob
mark :3
data 10
nukeme v1
commit refs/heads/master
mark :4
author Full Name <user@organization.tld> 2000010000 +0100
committer Full Name <user@organization.tld> 2000010000 +0100
data 2
B
from :2
M 100644 :3 moduleB/nukeme
blob
mark :5
data 10
nukeme v2
commit refs/heads/master
mark :6
author Full Name <user@organization.tld> 2000020000 +0100
committer Full Name <user@organization.tld> 2000020000 +0100
data 2
C
from :2
M 100644 :5 moduleB/nukeme
commit refs/heads/master
mark :7
author Full Name <user@organization.tld> 2000030000 +0100
committer Full Name <user@organization.tld> 2000030000 +0100
data 29
D: Merge commit 'C' into 'B'
from :4
merge :6
blob
mark :8
data 10
nukeme v3
commit refs/heads/master
mark :9
author Full Name <user@organization.tld> 2000040000 +0100
committer Full Name <user@organization.tld> 2000040000 +0100
data 2
F
from :7
M 100644 :8 moduleB/nukeme
blob
mark :10
data 10
keepme v2
commit refs/heads/master
mark :11
author Full Name <user@organization.tld> 2000050000 +0100
committer Full Name <user@organization.tld> 2000050000 +0100
data 2
G
from :9
M 100644 :10 moduleA/keepme
blob
mark :12
data 10
nukem4 v4
commit refs/heads/master
mark :13
author Full Name <user@organization.tld> 2000060000 +0100
committer Full Name <user@organization.tld> 2000060000 +0100
data 2
H
from :11
M 100644 :12 moduleB/nukeme
commit refs/heads/branchI
mark :14
author Full Name <user@organization.tld> 2000070000 +0100
committer Full Name <user@organization.tld> 2000070000 +0100
data 29
I: Merge commit 'D' into 'H'
from :13
merge :7
commit refs/heads/master
mark :15
author Full Name <user@organization.tld> 2000080000 +0100
committer Full Name <user@organization.tld> 2000080000 +0100
data 29
J: Merge commit 'H' into 'D'
from :7
merge :13
blob
mark :16
data 10
nukeme v4
commit refs/heads/master
mark :17
author Full Name <user@organization.tld> 2000090000 +0100
committer Full Name <user@organization.tld> 2000090000 +0100
data 2
K
from :15
M 100644 :16 moduleB/nukeme
blob
mark :18
data 10
keepme v3
commit refs/heads/master
mark :19
author Full Name <user@organization.tld> 2000092000 +0100
committer Full Name <user@organization.tld> 2000092000 +0100
data 2
L
from :17
M 100644 :18 moduleA/keepme
blob
mark :20
data 10
nukeme v5
commit refs/heads/master
mark :21
author Full Name <user@organization.tld> 2000094000 +0100
committer Full Name <user@organization.tld> 2000094000 +0100
data 2
M
from :19
M 100644 :20 moduleB/nukeme
blob
mark :22
data 10
nukeme v6
commit refs/heads/master
mark :23
author Full Name <user@organization.tld> 2000096000 +0100
committer Full Name <user@organization.tld> 2000096000 +0100
data 2
N
from :6
M 100644 :22 moduleB/nukeme
commit refs/heads/branchO
mark :24
author Full Name <user@organization.tld> 2000098000 +0100
committer Full Name <user@organization.tld> 2000098000 +0100
data 29
O: Merge commit 'N' into 'M'
from :21
merge :23
commit refs/heads/master
mark :25
author Full Name <user@organization.tld> 2000099000 +0100
committer Full Name <user@organization.tld> 2000099000 +0100
data 29
P: Merge commit 'M' into 'N'
from :23
merge :21
blob
mark :26
data 10
keepme v4
commit refs/heads/master
mark :27
author Full Name <user@organization.tld> 3000000000 +0100
committer Full Name <user@organization.tld> 3000000000 +0100
data 2
Q
from :25
M 100644 :26 moduleA/keepme
blob
mark :28
data 10
nukeme v7
commit refs/heads/master
mark :29
author Full Name <user@organization.tld> 3000010000 +0100
committer Full Name <user@organization.tld> 3000010000 +0100
data 2
R
from :27
M 100644 :28 moduleB/nukeme
commit refs/heads/master
mark :30
author Full Name <user@organization.tld> 3000020000 +0100
committer Full Name <user@organization.tld> 3000020000 +0100
data 29
S: Merge commit 'R' into 'R'
from :29
merge :29
blob
mark :31
data 10
keepme v5
commit refs/heads/master
mark :32
author Full Name <user@organization.tld> 3000030000 +0100
committer Full Name <user@organization.tld> 3000030000 +0100
data 2
T
from :30
M 100644 :31 moduleA/keepme
blob
mark :33
data 10
nukeme v8
commit refs/heads/master
mark :34
author Full Name <user@organization.tld> 3000050000 +0100
committer Full Name <user@organization.tld> 3000050000 +0100
data 29
V: Merge commit 'U' into 'U'
from :32
merge :32
M 100644 :33 moduleB/nukeme
blob
mark :35
data 10
keepme v6
commit refs/heads/master
mark :36
author Full Name <user@organization.tld> 3000060000 +0100
committer Full Name <user@organization.tld> 3000060000 +0100
data 2
W
from :34
M 100644 :35 moduleA/keepme
done

104
t/t9390/degenerate-keepme Normal file
View File

@ -0,0 +1,104 @@
feature done
blob
mark :1
data 10
keepme v1
reset refs/heads/branchO
commit refs/heads/branchO
mark :2
author Full Name <user@organization.tld> 2000000000 +0100
committer Full Name <user@organization.tld> 2000000000 +0100
data 2
A
M 100644 :1 moduleA/keepme
blob
mark :3
data 10
keepme v2
commit refs/heads/branchO
mark :4
author Full Name <user@organization.tld> 2000050000 +0100
committer Full Name <user@organization.tld> 2000050000 +0100
data 2
G
from :2
M 100644 :3 moduleA/keepme
commit refs/heads/branchI
mark :5
author Full Name <user@organization.tld> 2000070000 +0100
committer Full Name <user@organization.tld> 2000070000 +0100
data 29
I: Merge commit 'D' into 'H'
from :4
merge :2
commit refs/heads/branchO
mark :6
author Full Name <user@organization.tld> 2000080000 +0100
committer Full Name <user@organization.tld> 2000080000 +0100
data 29
J: Merge commit 'H' into 'D'
from :2
merge :4
blob
mark :7
data 10
keepme v3
commit refs/heads/branchO
mark :8
author Full Name <user@organization.tld> 2000092000 +0100
committer Full Name <user@organization.tld> 2000092000 +0100
data 2
L
from :6
M 100644 :7 moduleA/keepme
blob
mark :9
data 10
keepme v4
commit refs/heads/master
mark :10
author Full Name <user@organization.tld> 3000000000 +0100
committer Full Name <user@organization.tld> 3000000000 +0100
data 2
Q
from :8
M 100644 :9 moduleA/keepme
blob
mark :11
data 10
keepme v5
commit refs/heads/master
mark :12
author Full Name <user@organization.tld> 3000030000 +0100
committer Full Name <user@organization.tld> 3000030000 +0100
data 2
T
from :10
M 100644 :11 moduleA/keepme
blob
mark :13
data 10
keepme v6
commit refs/heads/master
mark :14
author Full Name <user@organization.tld> 3000060000 +0100
committer Full Name <user@organization.tld> 3000060000 +0100
data 2
W
from :12
M 100644 :13 moduleA/keepme
done

194
t/t9390/degenerate-moduleA Normal file
View File

@ -0,0 +1,194 @@
feature done
blob
mark :1
data 10
keepme v1
reset refs/heads/master
commit refs/heads/master
mark :2
author Full Name <user@organization.tld> 2000000000 +0100
committer Full Name <user@organization.tld> 2000000000 +0100
data 2
A
M 100644 :1 moduleA/keepme
blob
mark :3
data 13
sometimes v1
commit refs/heads/master
mark :4
author Full Name <user@organization.tld> 2000030000 +0100
committer Full Name <user@organization.tld> 2000030000 +0100
data 29
D: Merge commit 'C' into 'B'
from :2
merge :2
M 100644 :3 moduleA/sometimes
blob
mark :5
data 10
keepme v2
commit refs/heads/master
mark :6
author Full Name <user@organization.tld> 2000050000 +0100
committer Full Name <user@organization.tld> 2000050000 +0100
data 2
G
from :4
M 100644 :5 moduleA/keepme
blob
mark :7
data 13
sometimes v2
commit refs/heads/branchI
mark :8
author Full Name <user@organization.tld> 2000070000 +0100
committer Full Name <user@organization.tld> 2000070000 +0100
data 29
I: Merge commit 'D' into 'H'
from :6
merge :4
M 100644 :7 moduleA/sometimes
blob
mark :9
data 13
sometimes v3
commit refs/heads/master
mark :10
author Full Name <user@organization.tld> 2000080000 +0100
committer Full Name <user@organization.tld> 2000080000 +0100
data 29
J: Merge commit 'H' into 'D'
from :4
merge :6
M 100644 :9 moduleA/sometimes
blob
mark :11
data 10
keepme v3
commit refs/heads/master
mark :12
author Full Name <user@organization.tld> 2000092000 +0100
committer Full Name <user@organization.tld> 2000092000 +0100
data 2
L
from :10
M 100644 :11 moduleA/keepme
commit refs/heads/branchO
mark :13
author Full Name <user@organization.tld> 2000098000 +0100
committer Full Name <user@organization.tld> 2000098000 +0100
data 29
O: Merge commit 'N' into 'M'
from :12
merge :2
D moduleA/sometimes
blob
mark :14
data 13
sometimes v5
commit refs/heads/master
mark :15
author Full Name <user@organization.tld> 2000099000 +0100
committer Full Name <user@organization.tld> 2000099000 +0100
data 29
P: Merge commit 'M' into 'N'
from :2
merge :12
M 100644 :14 moduleA/sometimes
blob
mark :16
data 10
keepme v4
commit refs/heads/master
mark :17
author Full Name <user@organization.tld> 3000000000 +0100
committer Full Name <user@organization.tld> 3000000000 +0100
data 2
Q
from :15
M 100644 :16 moduleA/keepme
blob
mark :18
data 13
sometimes v6
commit refs/heads/master
mark :19
author Full Name <user@organization.tld> 3000020000 +0100
committer Full Name <user@organization.tld> 3000020000 +0100
data 29
S: Merge commit 'R' into 'R'
from :17
merge :17
M 100644 :18 moduleA/sometimes
blob
mark :20
data 10
keepme v5
commit refs/heads/master
mark :21
author Full Name <user@organization.tld> 3000030000 +0100
committer Full Name <user@organization.tld> 3000030000 +0100
data 2
T
from :19
M 100644 :20 moduleA/keepme
blob
mark :22
data 13
sometimes v7
commit refs/heads/master
mark :23
author Full Name <user@organization.tld> 3000040000 +0100
committer Full Name <user@organization.tld> 3000040000 +0100
data 2
U
from :21
M 100644 :22 moduleA/sometimes
commit refs/heads/master
mark :24
author Full Name <user@organization.tld> 3000050000 +0100
committer Full Name <user@organization.tld> 3000050000 +0100
data 29
V: Merge commit 'U' into 'U'
from :23
merge :23
blob
mark :25
data 10
keepme v6
commit refs/heads/master
mark :26
author Full Name <user@organization.tld> 3000060000 +0100
committer Full Name <user@organization.tld> 3000060000 +0100
data 2
W
from :24
M 100644 :25 moduleA/keepme
done