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 fa16ab36ad ("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 <lukeshu@datawire.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Luke Shumaker committed Apr 27, 2021 at 15:17 UTC f1cd2d93c207a0db5d85bcaf5a7b71ea60ceecb5
1 file changed +6 -40
contrib/subtree/t/t7900-subtree.sh
+6 -40
@@ -22,33 +22,6 @@ subtree_test_create_repo () {
22 git -C "$1" config log.date relative
23 }
24
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 -
25 test_create_commit () (
26 repo=$1 &&
27 commit=$2 &&
@@ -869,19 +842,12 @@ test_expect_success 'verify one file change per commit' '
842 cd "$test_count" &&
843 git subtree split --prefix="sub dir2" --branch subproj2-br &&
844
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
851 )
852 '
853