@@ -13,24 +13,44 @@ test_expect_success 'setup bare remotes' '
13
13
git push parent2 HEAD
14
14
'
15
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
+
16
40
test_expect_success ' "upstream" pushes to configured upstream' '
17
41
git checkout master &&
18
42
test_config branch.master.remote parent1 &&
19
43
test_config branch.master.merge refs/heads/foo &&
20
- test_config push.default upstream &&
21
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
26
46
'
27
47
28
48
test_expect_success ' "upstream" does not push on unconfigured remote' '
29
49
git checkout master &&
30
50
test_unconfig branch.master.remote &&
31
51
test_config push.default upstream &&
32
52
test_commit three &&
33
- test_must_fail git push
53
+ test_push_failure upstream
34
54
'
35
55
36
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' '
39
59
test_unconfig branch.master.merge &&
40
60
test_config push.default upstream
41
61
test_commit four &&
42
- test_must_fail git push
62
+ test_push_failure upstream
43
63
'
44
64
45
65
test_expect_success ' "upstream" does not push when remotes do not match' '
0 commit comments