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