t5528-push-default.sh: add helper functions
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Apr 24, 2012 at 09:50 UTC
321e75c5dc6d6abc76e2349000e93c809ddfcdab
1 file changed
+27
-7
t/t5528-push-default.sh
+27
-7
@@ -13,16 +13,36 @@ test_expect_success 'setup bare remotes' '
13
git push parent2 HEAD
14
'
15
16
+# $1 = local revision
17
+# $2 = remote revision (tested to be equal to the local one)
18
+check_pushed_commit () {
19
+ git log -1 --format='%h %s' "$1" >expect &&
20
+ git --git-dir=repo1 log -1 --format='%h %s' "$2" >actual &&
21
+ test_cmp expect actual
22
+}
23
+
24
+# $1 = push.default value
25
+# $2 = expected target branch for the push
26
+test_push_success () {
27
+ git -c push.default="$1" push &&
28
+ check_pushed_commit HEAD "$2"
29
+}
30
+
31
+# $1 = push.default value
32
+# check that push fails and does not modify any remote branch
33
+test_push_failure () {
34
+ git --git-dir=repo1 log --no-walk --format='%h %s' --all >expect &&
35
+ test_must_fail git -c push.default="$1" push &&
36
+ git --git-dir=repo1 log --no-walk --format='%h %s' --all >actual &&
37
+ test_cmp expect actual
38
+}
39
+
40
test_expect_success '"upstream" pushes to configured upstream' '
41
git checkout master &&
42
test_config branch.master.remote parent1 &&
43
test_config branch.master.merge refs/heads/foo &&
20
- test_config push.default upstream &&
44
test_commit two &&
22
- git push &&
23
- echo two >expect &&
24
- git --git-dir=repo1 log -1 --format=%s foo >actual &&
25
- test_cmp expect actual
45
+ test_push_success upstream foo
46
'
47
48
test_expect_success '"upstream" does not push on unconfigured remote' '
@@ -30,7 +50,7 @@ test_expect_success '"upstream" does not push on unconfigured remote' '
50
test_unconfig branch.master.remote &&
51
test_config push.default upstream &&
52
test_commit three &&
33
- test_must_fail git push
53
+ test_push_failure upstream
54
'
55
56
test_expect_success '"upstream" does not push on unconfigured branch' '
@@ -39,7 +59,7 @@ test_expect_success '"upstream" does not push on unconfigured branch' '
59
test_unconfig branch.master.merge &&
60
test_config push.default upstream
61
test_commit four &&
42
- test_must_fail git push
62
+ test_push_failure upstream
63
'
64
65
test_expect_success '"upstream" does not push when remotes do not match' '