Consolidate cat+grep calls into just grep.
[git-central.git] / tests / t2202-server-post-receive-email-branches.sh
1 #!/bin/sh
2
3 test_description='server post-receive email notification'
4
5 . ./test-lib.sh
6
7 export USER=author
8
9 test_expect_success 'setup' '
10         echo "setup" >a &&
11         git add a &&
12         git commit -m "setup" &&
13         git clone ./. server &&
14         rm -fr server/.git/hooks &&
15         git remote add origin ./server &&
16         git config --add branch.master.remote origin &&
17         git config --add branch.master.merge refs/heads/master &&
18         GIT_DIR=./server/.git git config --add hooks.post-receive-email.mailinglist commits@list.com &&
19         GIT_DIR=./server/.git git config --add hooks.post-receive-email.debug true &&
20         GIT_DIR=.
21         echo cbas >./server/.git/description
22 '
23
24 install_post_receive_hook 'post-receive-email'
25
26 test_expect_success 'create branch' '
27         git checkout -b topic master &&
28         echo "$test_name" >a &&
29         git commit -a -m "$test_name on topic" &&
30         prior_commit_hash=$(git rev-parse HEAD) &&
31         prior_commit_date=$(git log -n 1 --pretty=format:%cd HEAD) &&
32
33         echo "$test_name 2" >a &&
34         git commit -a -m "$test_name on topic 2 " &&
35         new_commit_hash=$(git rev-parse HEAD) &&
36         new_commit_abbrev=$(git rev-parse --short HEAD) &&
37         new_commit_date=$(git log -n 1 --pretty=format:%cd HEAD) &&
38
39         git push origin topic &&
40
41         interpolate ../t2202-1.txt 1.txt new_commit_hash new_commit_abbrev new_commit_date prior_commit_hash prior_commit_date &&
42         test_cmp 1.txt server/.git/refs.heads.topic.out
43 '
44
45 test_expect_success 'create branch with existing commits does not replay them' '
46         git checkout -b topic2 topic &&
47         existing_commit_hash=$(git rev-parse HEAD) &&
48         existing_commit_abbrev=$(git rev-parse --short HEAD) &&
49         existing_commit_date=$(git log -n 1 --pretty=format:%cd HEAD) &&
50
51         git push origin topic2 &&
52
53         interpolate ../t2202-3.txt 3.txt existing_commit_hash existing_commit_abbrev existing_commit_date &&
54         test_cmp 3.txt server/.git/refs.heads.topic2.out
55 '
56
57 test_expect_success 'update branch with existing commits does not replay them' '
58         # Put a commit on topic2, then fast foward topic to it
59         git checkout topic2 &&
60         echo "$test_name" >a &&
61         git commit -a -m "$test_name on topic" &&
62         git push &&
63
64         git checkout topic &&
65         old_commit_hash=$(git rev-parse HEAD) &&
66         old_commit_abbrev=$(git rev-parse --short HEAD) &&
67         git merge topic2 &&
68         existing_commit_hash=$(git rev-parse HEAD) &&
69         existing_commit_abbrev=$(git rev-parse --short HEAD) &&
70         git push &&
71
72         interpolate ../t2202-4.txt 4.txt old_commit_hash old_commit_abbrev existing_commit_hash existing_commit_abbrev &&
73         test_cmp 4.txt server/.git/refs.heads.topic.out
74 '
75
76 test_expect_success 'rewind branch' '
77         git checkout topic &&
78         old_commit_hash=$(git rev-parse HEAD) &&
79         old_commit_abbrev=$(git rev-parse --short HEAD) &&
80
81         git reset --hard HEAD^ &&
82         git push --force &&
83         new_commit_hash=$(git rev-parse HEAD) &&
84
85         interpolate ../t2202-5.txt 5.txt old_commit_hash new_commit_hash old_commit_abbrev &&
86         test_cmp 5.txt server/.git/refs.heads.topic.out
87 '
88
89 test_expect_success 'rewind and continue branch' '
90         git checkout topic &&
91         old_commit_hash=$(git rev-parse HEAD) &&
92         old_commit_abbrev=$(git rev-parse --short HEAD) &&
93
94         git reset --hard HEAD^ &&
95         echo "$test_name" >a &&
96         git commit -a -m "$test_name on topic" &&
97         new_commit_hash=$(git rev-parse HEAD) &&
98         new_commit_abbrev=$(git rev-parse --short HEAD) &&
99         new_commit_date=$(git log -n 1 --pretty=format:%cd HEAD) &&
100
101         git push --force &&
102         interpolate ../t2202-6.txt 6.txt old_commit_hash new_commit_hash new_commit_date new_commit_abbrev old_commit_abbrev &&
103         test_cmp 6.txt server/.git/refs.heads.topic.out
104 '
105
106 test_expect_success 'delete branch' '
107         old_commit_hash=$(git rev-parse HEAD) &&
108         git push origin :refs/heads/topic &&
109
110         interpolate ../t2202-2.txt 2.txt old_commit_hash &&
111         test_cmp 2.txt server/.git/refs.heads.topic.out
112 '
113
114 test_done
115