]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3436-rebase-more-options.sh
Merge branch 'ew/fetch-no-write-fetch-head-fix'
[thirdparty/git.git] / t / t3436-rebase-more-options.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Rohit Ashiwal
4 #
5
6 test_description='tests to ensure compatibility between am and interactive backends'
7
8 . ./test-lib.sh
9
10 . "$TEST_DIRECTORY"/lib-rebase.sh
11
12 GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
13 export GIT_AUTHOR_DATE
14
15 # This is a special case in which both am and interactive backends
16 # provide the same output. It was done intentionally because
17 # both the backends fall short of optimal behaviour.
18 test_expect_success 'setup' '
19 git checkout -b topic &&
20 test_write_lines "line 1" " line 2" "line 3" >file &&
21 git add file &&
22 git commit -m "add file" &&
23
24 test_write_lines "line 1" "new line 2" "line 3" >file &&
25 git commit -am "update file" &&
26 git tag side &&
27 test_commit commit1 foo foo1 &&
28 test_commit commit2 foo foo2 &&
29 test_commit commit3 foo foo3 &&
30
31 git checkout --orphan main &&
32 rm foo &&
33 test_write_lines "line 1" " line 2" "line 3" >file &&
34 git commit -am "add file" &&
35 git tag main &&
36
37 mkdir test-bin &&
38 write_script test-bin/git-merge-test <<-\EOF
39 exec git merge-recursive "$@"
40 EOF
41 '
42
43 test_expect_success 'bad -X <strategy-option> arguments: unclosed quote' '
44 cat >expect <<-\EOF &&
45 fatal: could not split '\''--bad'\'': unclosed quote
46 EOF
47 test_expect_code 128 git rebase -X"bad argument\"" side main >out 2>actual &&
48 test_must_be_empty out &&
49 test_cmp expect actual
50 '
51
52 test_expect_success 'bad -X <strategy-option> arguments: bad escape' '
53 cat >expect <<-\EOF &&
54 fatal: could not split '\''--bad'\'': cmdline ends with \
55 EOF
56 test_expect_code 128 git rebase -X"bad escape \\" side main >out 2>actual &&
57 test_must_be_empty out &&
58 test_cmp expect actual
59 '
60
61 test_expect_success '--ignore-whitespace works with apply backend' '
62 test_must_fail git rebase --apply main side &&
63 git rebase --abort &&
64 git rebase --apply --ignore-whitespace main side &&
65 git diff --exit-code side
66 '
67
68 test_expect_success '--ignore-whitespace works with merge backend' '
69 test_must_fail git rebase --merge main side &&
70 git rebase --abort &&
71 git rebase --merge --ignore-whitespace main side &&
72 git diff --exit-code side
73 '
74
75 test_expect_success '--ignore-whitespace is remembered when continuing' '
76 (
77 set_fake_editor &&
78 FAKE_LINES="break 1" git rebase -i --ignore-whitespace \
79 main side &&
80 git rebase --continue
81 ) &&
82 git diff --exit-code side
83 '
84
85 test_ctime_is_atime () {
86 git log $1 --format="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> %ai" >authortime &&
87 git log $1 --format="%cn <%ce> %ci" >committertime &&
88 test_cmp authortime committertime
89 }
90
91 test_expect_success '--committer-date-is-author-date works with apply backend' '
92 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
93 git rebase --apply --committer-date-is-author-date HEAD^ &&
94 test_ctime_is_atime -1
95 '
96
97 test_expect_success '--committer-date-is-author-date works with merge backend' '
98 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
99 git rebase -m --committer-date-is-author-date HEAD^ &&
100 test_ctime_is_atime -1
101 '
102
103 test_expect_success '--committer-date-is-author-date works when rewording' '
104 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
105 (
106 set_fake_editor &&
107 FAKE_COMMIT_MESSAGE=edited \
108 FAKE_LINES="reword 1" \
109 git rebase -i --committer-date-is-author-date HEAD^
110 ) &&
111 test_write_lines edited "" >expect &&
112 git log --format="%B" -1 >actual &&
113 test_cmp expect actual &&
114 test_ctime_is_atime -1
115 '
116
117 test_expect_success '--committer-date-is-author-date works with rebase -r' '
118 git checkout side &&
119 GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
120 git rebase -r --root --committer-date-is-author-date &&
121 test_ctime_is_atime
122 '
123
124 test_expect_success '--committer-date-is-author-date works when forking merge' '
125 git checkout side &&
126 GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
127 PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
128 --committer-date-is-author-date &&
129 test_ctime_is_atime
130 '
131
132 test_expect_success '--committer-date-is-author-date works when committing conflict resolution' '
133 git checkout commit2 &&
134 GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
135 test_must_fail git rebase -m --committer-date-is-author-date \
136 --onto HEAD^^ HEAD^ &&
137 echo resolved > foo &&
138 git add foo &&
139 git rebase --continue &&
140 test_ctime_is_atime -1
141 '
142
143 # Checking for +0000 in the author date is sufficient since the
144 # default timezone is UTC but the timezone used while committing is
145 # +0530. The inverted logic in the grep is necessary to check all the
146 # author dates in the file.
147 test_atime_is_ignored () {
148 git log $1 --format=%ai >authortime &&
149 ! grep -v +0000 authortime
150 }
151
152 test_expect_success '--reset-author-date works with apply backend' '
153 git commit --amend --date="$GIT_AUTHOR_DATE" &&
154 git rebase --apply --reset-author-date HEAD^ &&
155 test_atime_is_ignored -1
156 '
157
158 test_expect_success '--reset-author-date works with merge backend' '
159 git commit --amend --date="$GIT_AUTHOR_DATE" &&
160 git rebase --reset-author-date -m HEAD^ &&
161 test_atime_is_ignored -1
162 '
163
164 test_expect_success '--reset-author-date works after conflict resolution' '
165 test_must_fail git rebase --reset-author-date -m \
166 --onto commit2^^ commit2^ commit2 &&
167 echo resolved >foo &&
168 git add foo &&
169 git rebase --continue &&
170 test_atime_is_ignored -1
171 '
172
173 test_expect_success '--reset-author-date works with rebase -r' '
174 git checkout side &&
175 git merge --no-ff commit3 &&
176 git rebase -r --root --reset-author-date &&
177 test_atime_is_ignored
178 '
179
180 test_expect_success '--reset-author-date with --committer-date-is-author-date works' '
181 test_must_fail git rebase -m --committer-date-is-author-date \
182 --reset-author-date --onto commit2^^ commit2^ commit3 &&
183 git checkout --theirs foo &&
184 git add foo &&
185 git rebase --continue &&
186 test_ctime_is_atime -2 &&
187 test_atime_is_ignored -2
188 '
189
190 test_expect_success 'reset-author-date with --committer-date-is-author-date works when rewording' '
191 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
192 (
193 set_fake_editor &&
194 FAKE_COMMIT_MESSAGE=edited \
195 FAKE_LINES="reword 1" \
196 git rebase -i --committer-date-is-author-date \
197 --reset-author-date HEAD^
198 ) &&
199 test_write_lines edited "" >expect &&
200 git log --format="%B" -1 >actual &&
201 test_cmp expect actual &&
202 test_atime_is_ignored -1
203 '
204
205 test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
206 GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
207 PATH="./test-bin:$PATH" git rebase -i --strategy=test \
208 --reset-author-date \
209 --committer-date-is-author-date side side &&
210 test_ctime_is_atime -1 &&
211 test_atime_is_ignored -1
212 '
213
214 test_expect_success '--ignore-date is an alias for --reset-author-date' '
215 git commit --amend --date="$GIT_AUTHOR_DATE" &&
216 git rebase --apply --ignore-date HEAD^ &&
217 git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" &&
218 git rebase -m --ignore-date HEAD^ &&
219 test_atime_is_ignored -2
220 '
221
222 # This must be the last test in this file
223 test_expect_success '$EDITOR and friends are unchanged' '
224 test_editor_unchanged
225 '
226
227 test_done