t5403: simplify by using a single repository
There is no strong reason to use separate clones to run these tests; just use a single test repository prepared with more modern test_commit shell helper function. While at it, replace three "awk '{print $N}'" on the same file with shell built-in "read" into three variables. Revert d42ec126aa717d00549e387d5a95fd55683c2e2c which is a workaround for Cygwin that is no longer needed. Signed-off-by: Orgad Shaneh <orgads@gmail.com> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Orgad Shaneh committed
Dec 29, 2018 at 23:37 UTC
10499a9d586b3fba4ea6f67cd0b391b9e7048f34
1 file changed
+23
-55
t/t5403-post-checkout-hook.sh
+23
-55
@@ -7,82 +7,50 @@ test_description='Test the post-checkout hook.'
7
. ./test-lib.sh
8
9
test_expect_success setup '
10
- echo Data for commit0. >a &&
11
- echo Data for commit0. >b &&
12
- git update-index --add a &&
13
- git update-index --add b &&
14
- tree0=$(git write-tree) &&
15
- commit0=$(echo setup | git commit-tree $tree0) &&
16
- git update-ref refs/heads/master $commit0 &&
17
- git clone ./. clone1 &&
18
- git clone ./. clone2 &&
19
- GIT_DIR=clone2/.git git branch new2 &&
20
- echo Data for commit1. >clone2/b &&
21
- GIT_DIR=clone2/.git git add clone2/b &&
22
- GIT_DIR=clone2/.git git commit -m new2
23
-'
24
-
25
-for clone in 1 2; do
26
- cat >clone${clone}/.git/hooks/post-checkout <<'EOF'
27
-#!/bin/sh
28
-echo $@ > $GIT_DIR/post-checkout.args
29
-EOF
30
- chmod u+x clone${clone}/.git/hooks/post-checkout
31
-done
32
-
33
-test_expect_success 'post-checkout runs as expected ' '
34
- GIT_DIR=clone1/.git git checkout master &&
35
- test -e clone1/.git/post-checkout.args
10
+ mkdir -p .git/hooks &&
11
+ write_script .git/hooks/post-checkout <<-\EOF &&
12
+ echo "$@" >.git/post-checkout.args
13
+ EOF
14
+ test_commit one &&
15
+ test_commit two &&
16
+ test_commit three
17
'
18
19
test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '
39
- old=$(awk "{print \$1}" clone1/.git/post-checkout.args) &&
40
- new=$(awk "{print \$2}" clone1/.git/post-checkout.args) &&
41
- flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) &&
20
+ test_when_finished "rm -f .git/post-checkout.args" &&
21
+ git checkout master &&
22
+ read old new flag <.git/post-checkout.args &&
23
test $old = $new && test $flag = 1
24
'
25
45
-test_expect_success 'post-checkout runs as expected ' '
46
- GIT_DIR=clone1/.git git checkout master &&
47
- test -e clone1/.git/post-checkout.args
48
-'
49
-
26
test_expect_success 'post-checkout args are correct with git checkout -b ' '
51
- GIT_DIR=clone1/.git git checkout -b new1 &&
52
- old=$(awk "{print \$1}" clone1/.git/post-checkout.args) &&
53
- new=$(awk "{print \$2}" clone1/.git/post-checkout.args) &&
54
- flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) &&
27
+ test_when_finished "rm -f .git/post-checkout.args" &&
28
+ git checkout -b new1 &&
29
+ read old new flag <.git/post-checkout.args &&
30
test $old = $new && test $flag = 1
31
'
32
33
test_expect_success 'post-checkout receives the right args with HEAD changed ' '
59
- GIT_DIR=clone2/.git git checkout new2 &&
60
- old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
61
- new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
62
- flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
34
+ test_when_finished "rm -f .git/post-checkout.args" &&
35
+ git checkout two &&
36
+ read old new flag <.git/post-checkout.args &&
37
test $old != $new && test $flag = 1
38
'
39
40
test_expect_success 'post-checkout receives the right args when not switching branches ' '
67
- GIT_DIR=clone2/.git git checkout master b &&
68
- old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
69
- new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
70
- flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
41
+ test_when_finished "rm -f .git/post-checkout.args" &&
42
+ git checkout master -- three.t &&
43
+ read old new flag <.git/post-checkout.args &&
44
test $old = $new && test $flag = 0
45
'
46
74
-if test "$(git config --bool core.filemode)" = true; then
75
-mkdir -p templates/hooks
76
-cat >templates/hooks/post-checkout <<'EOF'
77
-#!/bin/sh
78
-echo $@ > $GIT_DIR/post-checkout.args
79
-EOF
80
-chmod +x templates/hooks/post-checkout
81
-
47
test_expect_success 'post-checkout hook is triggered by clone' '
48
+ mkdir -p templates/hooks &&
49
+ write_script templates/hooks/post-checkout <<-\EOF &&
50
+ echo "$@" >$GIT_DIR/post-checkout.args
51
+ EOF
52
git clone --template=templates . clone3 &&
53
test -f clone3/.git/post-checkout.args
54
'
86
-fi
55
56
test_done