Diff options
| -rw-r--r-- | tests/setup.sh | 17 | |
| -rwxr-xr-x | tests/t0107-diff.sh | 11 | |
| -rwxr-xr-x | tests/t0108-rawdiff.sh | 18 | |
| -rwxr-xr-x | tests/t0109-patch.sh | 10 |
4 files changed, 25 insertions, 31 deletions
diff --git a/tests/setup.sh b/tests/setup.sh index ac6e293..a43bf01 100644 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -199,6 +199,23 @@ mkrepo() { ) } +# Creates a repository holding mkrepo's one commit, then a commit adding +# old.txt with ten numbered lines and one renaming it to new.txt. A command +# given second runs in the repository just before the rename is committed, +# so a test can put changes of its own into that commit. +mkrepo_renamed() { + mkrepo "$1" 1 && + ( + cd "$1" && + test_seq 1 10 >old.txt && + git add old.txt && + git commit -m "add old.txt" && + git mv old.txt new.txt && + eval "$2" && + git commit -am "rename old.txt" + ) +} + setup_repos() { mkdir cache && mkrepo repos/foo 5 >/dev/null && diff --git a/tests/t0107-diff.sh b/tests/t0107-diff.sh index d0296d5..a23327b 100755 --- a/tests/t0107-diff.sh +++ b/tests/t0107-diff.sh @@ -382,16 +382,7 @@ test_expect_success 'rename-limit bounds the renames a diff looks for' ' # diff runs over the whole commit to find the rename, so the commit changes # another file as well, which the limit still has to leave out. test_expect_success 'set up a renamed file' ' - mkrepo repos/moved 1 && - ( - cd repos/moved && - test_seq 1 10 >old.txt && - git add old.txt && - git commit -m "add old.txt" && - git mv old.txt new.txt && - echo changed >file-1 && - git commit -am "rename old.txt" - ) && + mkrepo_renamed repos/moved "echo changed >file-1" && cgitrc_repo movedrc moved ' diff --git a/tests/t0108-rawdiff.sh b/tests/t0108-rawdiff.sh index afd1ff1..23a41b4 100755 --- a/tests/t0108-rawdiff.sh +++ b/tests/t0108-rawdiff.sh @@ -46,24 +46,18 @@ test_expect_success 'a path limits the diff to that file' ' ' # The old name of a file renamed in the change joins the limit, so the diff -# shows the rename, the same as git diff given both names. +# shows the rename, the same as git diff given both names. The rename adds a +# line too, so git has to pair the files by similarity rather than as an +# exact match, and the last grep makes sure the line is there. test_expect_success 'a renamed file is diffed as the rename' ' - mkrepo repos/moved 1 && - ( - cd repos/moved && - test_seq 1 10 >old.txt && - git add old.txt && - git commit -m "add old.txt" && - git mv old.txt new.txt && - echo eleven >>new.txt && - git commit -am "rename old.txt" - ) && + mkrepo_renamed repos/moved "echo eleven >>new.txt" && cgitrc_repo movedrc moved && cgit_ok movedrc "url=moved/rawdiff/new.txt" >tmp && git -C repos/moved diff HEAD^ HEAD -- old.txt new.txt >expect && strip_headers <tmp >actual && test_cmp expect actual && - grep "^rename from old.txt$" actual + grep "^rename from old.txt$" actual && + grep "^+eleven$" actual ' test_done diff --git a/tests/t0109-patch.sh b/tests/t0109-patch.sh index 9077960..64d995c 100755 --- a/tests/t0109-patch.sh +++ b/tests/t0109-patch.sh @@ -140,15 +140,7 @@ test_expect_success 'enable-plain-email=0 leaves the address off the patch' ' # carries the rename rather than a file added whole. It matches git given both # names, but for the note naming the limit. test_expect_success 'a renamed file is patched as the rename' ' - mkrepo repos/moved 1 && - ( - cd repos/moved && - test_seq 1 10 >old.txt && - git add old.txt && - git commit -m "add old.txt" && - git mv old.txt new.txt && - git commit -m "rename old.txt" - ) && + mkrepo_renamed repos/moved && cgitrc_repo movedrc moved && cgit_ok movedrc "url=moved/patch/new.txt" >tmp && git -C repos/moved format-patch -1 -M --subject-prefix="" \ |
