Skip to content

Commit f1cd2d9

Browse files
LukeShugitster
authored andcommitted
subtree: t7900: fix 'verify one file change per commit'
As far as I can tell, this test isn't actually testing anything, because someone forgot to tack on `--name-only` to `git log`. This seems to have been the case since the test was first written, back in fa16ab3 ("test.sh: make sure no commit changes more than one file at a time.", 2009-04-26), unless `git log` used to do that by default and didn't need the flag back then? Convincing myself that it's not actually testing anything was tricky, the code is a little hard to reason about. It can be made a lot simpler if instead of trying to parse all of the info from a single `git log`, we're OK calling `git log` from inside of a loop. And it's my opinion that tests are not the place for clever optimized code. So, fix and simplify the test, so that it's actually testing something and is simpler to reason about. Signed-off-by: Luke Shumaker <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 63ac4f1 commit f1cd2d9

File tree

1 file changed

+6
-40
lines changed

1 file changed

+6
-40
lines changed

contrib/subtree/t/t7900-subtree.sh

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,6 @@ subtree_test_create_repo () {
2222
git -C "$1" config log.date relative
2323
}
2424

25-
# Make sure no patch changes more than one file.
26-
# The original set of commits changed only one file each.
27-
# A multi-file change would imply that we pruned commits
28-
# too aggressively.
29-
join_commits () {
30-
commit=
31-
all=
32-
while read x y
33-
do
34-
if test -z "$x"
35-
then
36-
continue
37-
elif test "$x" = "commit:"
38-
then
39-
if test -n "$commit"
40-
then
41-
echo "$commit $all"
42-
all=
43-
fi
44-
commit="$y"
45-
else
46-
all="$all $y"
47-
fi
48-
done
49-
echo "$commit $all"
50-
}
51-
5225
test_create_commit () (
5326
repo=$1 &&
5427
commit=$2 &&
@@ -869,19 +842,12 @@ test_expect_success 'verify one file change per commit' '
869842
cd "$test_count" &&
870843
git subtree split --prefix="sub dir2" --branch subproj2-br &&
871844
872-
x= &&
873-
git log --pretty=format:"commit: %H" | join_commits |
874-
(
875-
while read commit a b
876-
do
877-
test_debug "echo Verifying commit $commit"
878-
test_debug "echo a: $a"
879-
test_debug "echo b: $b"
880-
test "$b" = ""
881-
x=1
882-
done
883-
test "$x" = 1
884-
)
845+
git log --format="%H" >commit-list &&
846+
while read commit
847+
do
848+
git log -n1 --format="" --name-only "$commit" >file-list &&
849+
test_line_count -le 1 file-list || return 1
850+
done <commit-list
885851
)
886852
'
887853

0 commit comments

Comments
 (0)