]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5528-push-default.sh
push: change `simple` to accommodate triangular workflows
[thirdparty/git.git] / t / t5528-push-default.sh
CommitLineData
135dadef
JH
1#!/bin/sh
2
3test_description='check various push.default settings'
4. ./test-lib.sh
5
6test_expect_success 'setup bare remotes' '
7 git init --bare repo1 &&
8 git remote add parent1 repo1 &&
9 git init --bare repo2 &&
10 git remote add parent2 repo2 &&
11 test_commit one &&
12 git push parent1 HEAD &&
13 git push parent2 HEAD
14'
15
321e75c5
MM
16# $1 = local revision
17# $2 = remote revision (tested to be equal to the local one)
18check_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
26test_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
33test_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
135dadef
JH
40test_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 &&
135dadef 44 test_commit two &&
321e75c5 45 test_push_success upstream foo
135dadef
JH
46'
47
48test_expect_success '"upstream" does not push on unconfigured remote' '
49 git checkout master &&
50 test_unconfig branch.master.remote &&
135dadef 51 test_commit three &&
321e75c5 52 test_push_failure upstream
135dadef
JH
53'
54
55test_expect_success '"upstream" does not push on unconfigured branch' '
56 git checkout master &&
57 test_config branch.master.remote parent1 &&
58 test_unconfig branch.master.merge &&
135dadef 59 test_commit four &&
321e75c5 60 test_push_failure upstream
135dadef
JH
61'
62
63test_expect_success '"upstream" does not push when remotes do not match' '
64 git checkout master &&
65 test_config branch.master.remote parent1 &&
66 test_config branch.master.merge refs/heads/foo &&
67 test_config push.default upstream &&
68 test_commit five &&
69 test_must_fail git push parent2
70'
71
b55e6775
MM
72test_expect_success 'push from/to new branch with upstream, matching and simple' '
73 git checkout -b new-branch &&
74 test_push_failure simple &&
75 test_push_failure matching &&
76 test_push_failure upstream
77'
78
79test_expect_success 'push from/to new branch with current creates remote branch' '
80 test_config branch.new-branch.remote repo1 &&
81 git checkout new-branch &&
82 test_push_success current new-branch
83'
84
85test_expect_success 'push to existing branch, with no upstream configured' '
86 test_config branch.master.remote repo1 &&
87 git checkout master &&
88 test_push_failure simple &&
89 test_push_failure upstream
90'
91
92test_expect_success 'push to existing branch, upstream configured with same name' '
93 test_config branch.master.remote repo1 &&
94 test_config branch.master.merge refs/heads/master &&
95 git checkout master &&
96 test_commit six &&
97 test_push_success upstream master &&
98 test_commit seven &&
99 test_push_success simple master
100'
101
102test_expect_success 'push to existing branch, upstream configured with different name' '
103 test_config branch.master.remote repo1 &&
104 test_config branch.master.merge refs/heads/other-name &&
105 git checkout master &&
106 test_commit eight &&
107 test_push_success upstream other-name &&
108 test_commit nine &&
109 test_push_failure simple &&
110 git --git-dir=repo1 log -1 --format="%h %s" "other-name" >expect-other-name &&
111 test_push_success current master &&
112 git --git-dir=repo1 log -1 --format="%h %s" "other-name" >actual-other-name &&
113 test_cmp expect-other-name actual-other-name
114'
115
135dadef 116test_done