rev-list --min-parents,--max-parents: doc, test and completion
This also adds test for "--merges" and "--no-merges" which we did not have so far. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael J Gruber committed
Mar 23, 2011 at 10:38 UTC
6a6ebded7f2288d098f825f97cb2c210f0344497
4 files changed
+129
-3
Documentation/git-rev-list.txt
+4
@@ -16,6 +16,10 @@ SYNOPSIS
16
[ \--sparse ]
17
[ \--merges ]
18
[ \--no-merges ]
19
+ [ \--min-parents=<number> ]
20
+ [ \--no-min-parents ]
21
+ [ \--max-parents=<number> ]
22
+ [ \--no-max-parents ]
23
[ \--first-parent ]
24
[ \--remove-empty ]
25
[ \--full-history ]
Documentation/rev-list-options.txt
+17
-2
@@ -226,11 +226,26 @@ endif::git-rev-list[]
226
227
--merges::
228
229
- Print only merge commits.
229
+ Print only merge commits. This is exactly the same as `--min-parents=2`.
230
231
--no-merges::
232
233
- Do not print commits with more than one parent.
233
+ Do not print commits with more than one parent. This is
234
+ exactly the same as `--max-parents=1`.
235
+
236
+--min-parents=<number>::
237
+--max-parents=<number>::
238
+--no-min-parents::
239
+--no-max-parents::
240
+
241
+ Show only commits which have at least (or at most) that many
242
+ commits. In particular, `--max-parents=1` is the same as `--no-merges`,
243
+ `--min-parents=2` is the same as `--merges`. `--max-parents=0`
244
+ gives all root commits and `--min-parents=3` all octopus merges.
245
++
246
+`--no-min-parents` and `--no-max-parents` reset these limits (to no limit)
247
+again. Equivalent forms are `--min-parents=0` (any commit has 0 or more
248
+parents) and `--max-parents=-1` (negative numbers denote no upper limit).
249
250
--first-parent::
251
Follow only the first parent commit upon seeing a merge
contrib/completion/git-completion.bash
+2
@@ -1572,6 +1572,8 @@ __git_log_common_options="
1572
--max-count=
1573
--max-age= --since= --after=
1574
--min-age= --until= --before=
1575
+ --min-parents= --max-parents=
1576
+ --no-min-parents --no-max-parents
1577
"
1578
# Options that go well for log and gitk (not shortlog)
1579
__git_log_gitk_options="
t/t6009-rev-list-parent.sh
+106
-1
@@ -1,9 +1,17 @@
1
#!/bin/sh
2
3
-test_description='properly cull all ancestors'
3
+test_description='ancestor culling and limiting by parent number'
4
5
. ./test-lib.sh
6
7
+check_revlist () {
8
+ rev_list_args="$1" &&
9
+ shift &&
10
+ git rev-parse "$@" >expect &&
11
+ git rev-list $rev_list_args --all >actual &&
12
+ test_cmp expect actual
13
+}
14
+
15
test_expect_success setup '
16
17
touch file &&
@@ -28,4 +36,101 @@ test_expect_success 'one is ancestor of others and should not be shown' '
36
37
'
38
39
+test_expect_success 'setup roots, merges and octopuses' '
40
+
41
+ git checkout --orphan newroot &&
42
+ test_commit five &&
43
+ git checkout -b sidebranch two &&
44
+ test_commit six &&
45
+ git checkout -b anotherbranch three &&
46
+ test_commit seven &&
47
+ git checkout -b yetanotherbranch four &&
48
+ test_commit eight &&
49
+ git checkout master &&
50
+ test_merge normalmerge newroot &&
51
+ test_tick &&
52
+ git merge -m tripus sidebranch anotherbranch &&
53
+ git tag tripus &&
54
+ git checkout -b tetrabranch normalmerge &&
55
+ test_tick &&
56
+ git merge -m tetrapus sidebranch anotherbranch yetanotherbranch &&
57
+ git tag tetrapus &&
58
+ git checkout master
59
+'
60
+
61
+test_expect_success 'rev-list roots' '
62
+
63
+ check_revlist "--max-parents=0" one five
64
+'
65
+
66
+test_expect_success 'rev-list no merges' '
67
+
68
+ check_revlist "--max-parents=1" one eight seven six five four three two &&
69
+ check_revlist "--no-merges" one eight seven six five four three two
70
+'
71
+
72
+test_expect_success 'rev-list no octopuses' '
73
+
74
+ check_revlist "--max-parents=2" one normalmerge eight seven six five four three two
75
+'
76
+
77
+test_expect_success 'rev-list no roots' '
78
+
79
+ check_revlist "--min-parents=1" tetrapus tripus normalmerge eight seven six four three two
80
+'
81
+
82
+test_expect_success 'rev-list merges' '
83
+
84
+ check_revlist "--min-parents=2" tetrapus tripus normalmerge &&
85
+ check_revlist "--merges" tetrapus tripus normalmerge
86
+'
87
+
88
+test_expect_success 'rev-list octopus' '
89
+
90
+ check_revlist "--min-parents=3" tetrapus tripus
91
+'
92
+
93
+test_expect_success 'rev-list ordinary commits' '
94
+
95
+ check_revlist "--min-parents=1 --max-parents=1" eight seven six four three two
96
+'
97
+
98
+test_expect_success 'rev-list --merges --no-merges yields empty set' '
99
+
100
+ check_revlist "--min-parents=2 --no-merges" &&
101
+ check_revlist "--merges --no-merges" &&
102
+ check_revlist "--no-merges --merges"
103
+'
104
+
105
+test_expect_success 'rev-list override and infinities' '
106
+
107
+ check_revlist "--min-parents=2 --max-parents=1 --max-parents=3" tripus normalmerge &&
108
+ check_revlist "--min-parents=1 --min-parents=2 --max-parents=7" tetrapus tripus normalmerge &&
109
+ check_revlist "--min-parents=2 --max-parents=8" tetrapus tripus normalmerge &&
110
+ check_revlist "--min-parents=2 --max-parents=-1" tetrapus tripus normalmerge &&
111
+ check_revlist "--min-parents=2 --no-max-parents" tetrapus tripus normalmerge &&
112
+ check_revlist "--max-parents=0 --min-parents=1 --no-min-parents" one five
113
+'
114
+
115
+test_expect_success 'set up dodecapus' '
116
+
117
+ for i in 1 2 3 4 5 6 7 8 9 10 11
118
+ do
119
+ git checkout -b root$i five || return
120
+ test_commit $i || return
121
+ done &&
122
+ git checkout master &&
123
+ test_tick &&
124
+ git merge -m dodecapus root{1,2,3,4,5,6,7,8,9,10,11} &&
125
+ git tag dodecapus
126
+'
127
+
128
+test_expect_success 'test with dodecapus' '
129
+
130
+ check_revlist "--min-parents=4" dodecapus tetrapus &&
131
+ check_revlist "--min-parents=8" dodecapus &&
132
+ check_revlist "--min-parents=12" dodecapus &&
133
+ check_revlist "--min-parents=13" &&
134
+ check_revlist "--min-parents=4 --max-parents=11" tetrapus
135
+'
136
test_done