Skip to content

Commit cd63940

Browse files
committed
t5403: Refactor
* Replace multiple clones and commits by test_commits. * Replace 3 invocations of awk by read. Signed-off-by: Orgad Shaneh <[email protected]>
1 parent 7c9fbc0 commit cd63940

File tree

1 file changed

+18
-37
lines changed

1 file changed

+18
-37
lines changed

t/t5403-post-checkout-hook.sh

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,48 @@ test_description='Test the post-checkout hook.'
77
. ./test-lib.sh
88

99
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
10+
test_commit one &&
11+
test_commit two &&
12+
test_commit three three &&
13+
mv .git/hooks-disabled .git/hooks
2314
'
2415

25-
for clone in 1 2; do
26-
cat >clone${clone}/.git/hooks/post-checkout <<'EOF'
16+
cat >.git/hooks/post-checkout <<'EOF'
2717
#!/bin/sh
28-
echo $@ > $GIT_DIR/post-checkout.args
18+
echo $@ > .git/post-checkout.args
2919
EOF
30-
chmod u+x clone${clone}/.git/hooks/post-checkout
31-
done
20+
chmod u+x .git/hooks/post-checkout
3221

3322
test_expect_success 'post-checkout runs as expected ' '
34-
GIT_DIR=clone1/.git git checkout master &&
35-
test -e clone1/.git/post-checkout.args
23+
git checkout master &&
24+
test -e .git/post-checkout.args
3625
'
3726

3827
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) &&
28+
read old new flag < .git/post-checkout.args &&
4229
test $old = $new && test $flag = 1
4330
'
4431

4532
test_expect_success 'post-checkout runs as expected ' '
46-
GIT_DIR=clone1/.git git checkout master &&
47-
test -e clone1/.git/post-checkout.args
33+
git checkout master &&
34+
test -e .git/post-checkout.args
4835
'
4936

5037
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) &&
38+
git checkout -b new1 &&
39+
read old new flag < .git/post-checkout.args &&
5540
test $old = $new && test $flag = 1
5641
'
5742

5843
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) &&
44+
git checkout two &&
45+
read old new flag < .git/post-checkout.args &&
6346
test $old != $new && test $flag = 1
6447
'
6548

6649
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) &&
50+
git checkout master -- three &&
51+
read old new flag < .git/post-checkout.args &&
7152
test $old = $new && test $flag = 0
7253
'
7354

0 commit comments

Comments
 (0)