Raw
1 #!/bin/sh
2
3 test_description='push with --set-upstream'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY"/lib-terminal.sh
9
10 ensure_fresh_upstream() {
11 rm -rf parent && git init --bare parent
12 }
13
14 test_expect_success 'setup bare parent' '
15 ensure_fresh_upstream &&
16 git remote add upstream parent
17 '
18
19 test_expect_success 'setup local commit' '
20 echo content >file &&
21 git add file &&
22 git commit -m one
23 '
24
25 check_config() {
26 (echo $2; echo $3) >expect.$1
27 (git config branch.$1.remote
28 git config branch.$1.merge) >actual.$1
29 test_cmp expect.$1 actual.$1
30 }
31
32 test_expect_success 'push -u main:main' '
33 git push -u upstream main:main &&
34 check_config main upstream refs/heads/main
35 '
36
37 test_expect_success 'push -u main:other' '
38 git push -u upstream main:other &&
39 check_config main upstream refs/heads/other
40 '
41
42 test_expect_success 'push -u --dry-run main:otherX' '
43 git push -u --dry-run upstream main:otherX &&
44 check_config main upstream refs/heads/other
45 '
46
47 test_expect_success 'push -u topic_2:topic_2' '
48 git branch topic_2 &&
49 git push -u upstream topic_2:topic_2 &&
50 check_config topic_2 upstream refs/heads/topic_2
51 '
52
53 test_expect_success 'push -u topic_2:other2' '
54 git push -u upstream topic_2:other2 &&
55 check_config topic_2 upstream refs/heads/other2
56 '
57
58 test_expect_success 'push -u :topic_2' '
59 git push -u upstream :topic_2 &&
60 check_config topic_2 upstream refs/heads/other2
61 '
62
63 test_expect_success 'push -u --all(the same behavior with--branches)' '
64 git branch all1 &&
65 git branch all2 &&
66 git push -u --all &&
67 check_config all1 upstream refs/heads/all1 &&
68 check_config all2 upstream refs/heads/all2 &&
69 git config --get-regexp branch.all* > expect &&
70 git config --remove-section branch.all1 &&
71 git config --remove-section branch.all2 &&
72 git push -u --branches &&
73 check_config all1 upstream refs/heads/all1 &&
74 check_config all2 upstream refs/heads/all2 &&
75 git config --get-regexp branch.all* > actual &&
76 test_cmp expect actual
77 '
78
79 test_expect_success 'push -u HEAD' '
80 git checkout -b headbranch &&
81 git push -u upstream HEAD &&
82 check_config headbranch upstream refs/heads/headbranch
83 '
84
85 test_expect_success TTY 'progress messages go to tty' '
86 ensure_fresh_upstream &&
87
88 test_terminal git push -u upstream main >out 2>err &&
89 test_grep "Writing objects" err
90 '
91
92 test_expect_success 'progress messages do not go to non-tty' '
93 ensure_fresh_upstream &&
94
95 # skip progress messages, since stderr is non-tty
96 git push -u upstream main >out 2>err &&
97 test_grep ! "Writing objects" err
98 '
99
100 test_expect_success 'progress messages go to non-tty (forced)' '
101 ensure_fresh_upstream &&
102
103 # force progress messages to stderr, even though it is non-tty
104 git push -u --progress upstream main >out 2>err &&
105 test_grep "Writing objects" err
106 '
107
108 test_expect_success TTY 'push -q suppresses progress' '
109 ensure_fresh_upstream &&
110
111 test_terminal git push -u -q upstream main >out 2>err &&
112 test_grep ! "Writing objects" err
113 '
114
115 test_expect_success TTY 'push --no-progress suppresses progress' '
116 ensure_fresh_upstream &&
117
118 test_terminal git push -u --no-progress upstream main >out 2>err &&
119 test_grep ! "Unpacking objects" err &&
120 test_grep ! "Writing objects" err
121 '
122
123 test_expect_success TTY 'quiet push' '
124 ensure_fresh_upstream &&
125
126 test_terminal git push --quiet --no-progress upstream main >output 2>&1 &&
127 test_must_be_empty output
128 '
129
130 test_expect_success TTY 'quiet push -u' '
131 ensure_fresh_upstream &&
132
133 test_terminal git push --quiet -u --no-progress upstream main >output 2>&1 &&
134 test_must_be_empty output
135 '
136
137 test_done