The second batch
[git] / t / t5523-push-upstream.sh
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' '
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 '
70
71 test_expect_success 'push -u HEAD' '
72         git checkout -b headbranch &&
73         git push -u upstream HEAD &&
74         check_config headbranch upstream refs/heads/headbranch
75 '
76
77 test_expect_success TTY 'progress messages go to tty' '
78         ensure_fresh_upstream &&
79
80         test_terminal git push -u upstream main >out 2>err &&
81         test_i18ngrep "Writing objects" err
82 '
83
84 test_expect_success 'progress messages do not go to non-tty' '
85         ensure_fresh_upstream &&
86
87         # skip progress messages, since stderr is non-tty
88         git push -u upstream main >out 2>err &&
89         test_i18ngrep ! "Writing objects" err
90 '
91
92 test_expect_success 'progress messages go to non-tty (forced)' '
93         ensure_fresh_upstream &&
94
95         # force progress messages to stderr, even though it is non-tty
96         git push -u --progress upstream main >out 2>err &&
97         test_i18ngrep "Writing objects" err
98 '
99
100 test_expect_success TTY 'push -q suppresses progress' '
101         ensure_fresh_upstream &&
102
103         test_terminal git push -u -q upstream main >out 2>err &&
104         test_i18ngrep ! "Writing objects" err
105 '
106
107 test_expect_success TTY 'push --no-progress suppresses progress' '
108         ensure_fresh_upstream &&
109
110         test_terminal git push -u --no-progress upstream main >out 2>err &&
111         test_i18ngrep ! "Unpacking objects" err &&
112         test_i18ngrep ! "Writing objects" err
113 '
114
115 test_expect_success TTY 'quiet push' '
116         ensure_fresh_upstream &&
117
118         test_terminal git push --quiet --no-progress upstream main 2>&1 | tee output &&
119         test_must_be_empty output
120 '
121
122 test_expect_success TTY 'quiet push -u' '
123         ensure_fresh_upstream &&
124
125         test_terminal git push --quiet -u --no-progress upstream main 2>&1 | tee output &&
126         test_must_be_empty output
127 '
128
129 test_done