]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5574-fetch-output.sh
fetch: move option related variables into main function
[thirdparty/git.git] / t / t5574-fetch-output.sh
CommitLineData
2c5691d6
PS
1#!/bin/sh
2
3test_description='git fetch output format'
4
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8. ./test-lib.sh
9
3daf6558
PS
10test_expect_success 'fetch with invalid output format configuration' '
11 test_when_finished "rm -rf clone" &&
12 git clone . clone &&
13
14 test_must_fail git -C clone -c fetch.output fetch origin 2>actual.err &&
15 cat >expect <<-EOF &&
16 error: missing value for ${SQ}fetch.output${SQ}
17 fatal: unable to parse ${SQ}fetch.output${SQ} from command-line config
18 EOF
19 test_cmp expect actual.err &&
20
21 test_must_fail git -C clone -c fetch.output= fetch origin 2>actual.err &&
22 cat >expect <<-EOF &&
23 fatal: invalid value for ${SQ}fetch.output${SQ}: ${SQ}${SQ}
24 EOF
25 test_cmp expect actual.err &&
26
27 test_must_fail git -C clone -c fetch.output=garbage fetch origin 2>actual.err &&
28 cat >expect <<-EOF &&
29 fatal: invalid value for ${SQ}fetch.output${SQ}: ${SQ}garbage${SQ}
30 EOF
31 test_cmp expect actual.err
32'
33
2c5691d6
PS
34test_expect_success 'fetch aligned output' '
35 git clone . full-output &&
36 test_commit looooooooooooong-tag &&
37 (
38 cd full-output &&
39 git -c fetch.output=full fetch origin >actual 2>&1 &&
40 grep -e "->" actual | cut -c 22- >../actual
41 ) &&
42 cat >expect <<-\EOF &&
43 main -> origin/main
44 looooooooooooong-tag -> looooooooooooong-tag
45 EOF
46 test_cmp expect actual
47'
48
49test_expect_success 'fetch compact output' '
50 git clone . compact &&
51 test_commit extraaa &&
52 (
53 cd compact &&
54 git -c fetch.output=compact fetch origin >actual 2>&1 &&
55 grep -e "->" actual | cut -c 22- >../actual
56 ) &&
57 cat >expect <<-\EOF &&
58 main -> origin/*
59 extraaa -> *
60 EOF
61 test_cmp expect actual
62'
63
1c31764d
PS
64test_expect_success 'fetch output with HEAD' '
65 test_when_finished "rm -rf head" &&
66 git clone . head &&
67
68 git -C head fetch --dry-run origin HEAD >actual.out 2>actual.err &&
69 cat >expect <<-EOF &&
70 From $(test-tool path-utils real_path .)/.
71 * branch HEAD -> FETCH_HEAD
72 EOF
73 test_must_be_empty actual.out &&
74 test_cmp expect actual.err &&
75
76 git -C head fetch origin HEAD >actual.out 2>actual.err &&
77 test_must_be_empty actual.out &&
78 test_cmp expect actual.err &&
79
80 git -C head fetch --dry-run origin HEAD:foo >actual.out 2>actual.err &&
81 cat >expect <<-EOF &&
82 From $(test-tool path-utils real_path .)/.
83 * [new ref] HEAD -> foo
84 EOF
85 test_must_be_empty actual.out &&
86 test_cmp expect actual.err &&
87
88 git -C head fetch origin HEAD:foo >actual.out 2>actual.err &&
89 test_must_be_empty actual.out &&
90 test_cmp expect actual.err
91'
92
93test_expect_success 'fetch output with object ID' '
94 test_when_finished "rm -rf object-id" &&
95 git clone . object-id &&
96 commit=$(git rev-parse HEAD) &&
97
98 git -C object-id fetch --dry-run origin $commit:object-id >actual.out 2>actual.err &&
99 cat >expect <<-EOF &&
100 From $(test-tool path-utils real_path .)/.
101 * [new ref] $commit -> object-id
102 EOF
103 test_must_be_empty actual.out &&
104 test_cmp expect actual.err &&
105
106 git -C object-id fetch origin $commit:object-id >actual.out 2>actual.err &&
107 test_must_be_empty actual.out &&
108 test_cmp expect actual.err
109'
110
2c5691d6
PS
111test_expect_success '--no-show-forced-updates' '
112 mkdir forced-updates &&
113 (
114 cd forced-updates &&
115 git init &&
116 test_commit 1 &&
117 test_commit 2
118 ) &&
119 git clone forced-updates forced-update-clone &&
120 git clone forced-updates no-forced-update-clone &&
121 git -C forced-updates reset --hard HEAD~1 &&
122 (
123 cd forced-update-clone &&
124 git fetch --show-forced-updates origin 2>output &&
125 test_i18ngrep "(forced update)" output
126 ) &&
127 (
128 cd no-forced-update-clone &&
129 git fetch --no-show-forced-updates origin 2>output &&
130 test_i18ngrep ! "(forced update)" output
131 )
132'
133
134test_done