]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3436-rebase-more-options.sh
The third batch
[thirdparty/git.git] / t / t3436-rebase-more-options.sh
CommitLineData
ef484add
RA
1#!/bin/sh
2#
3# Copyright (c) 2019 Rohit Ashiwal
4#
5
6test_description='tests to ensure compatibility between am and interactive backends'
7
8. ./test-lib.sh
9
10. "$TEST_DIRECTORY"/lib-rebase.sh
11
7573cec5
PW
12GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
13export GIT_AUTHOR_DATE
14
ef484add
RA
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.
18test_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 &&
7573cec5
PW
27 test_commit commit1 foo foo1 &&
28 test_commit commit2 foo foo2 &&
29 test_commit commit3 foo foo3 &&
ef484add 30
d1c02d93 31 git checkout --orphan main &&
7573cec5 32 rm foo &&
ef484add
RA
33 test_write_lines "line 1" " line 2" "line 3" >file &&
34 git commit -am "add file" &&
7573cec5
PW
35 git tag main &&
36
37 mkdir test-bin &&
38 write_script test-bin/git-merge-test <<-\EOF
6160b2e9 39 exec git merge-recursive "$@"
7573cec5 40 EOF
ef484add
RA
41'
42
43test_expect_success '--ignore-whitespace works with apply backend' '
44 test_must_fail git rebase --apply main side &&
45 git rebase --abort &&
46 git rebase --apply --ignore-whitespace main side &&
47 git diff --exit-code side
48'
49
50test_expect_success '--ignore-whitespace works with merge backend' '
51 test_must_fail git rebase --merge main side &&
52 git rebase --abort &&
53 git rebase --merge --ignore-whitespace main side &&
54 git diff --exit-code side
55'
56
57test_expect_success '--ignore-whitespace is remembered when continuing' '
58 (
59 set_fake_editor &&
60 FAKE_LINES="break 1" git rebase -i --ignore-whitespace \
61 main side &&
62 git rebase --continue
63 ) &&
64 git diff --exit-code side
65'
66
7573cec5 67test_ctime_is_atime () {
56706dba
JK
68 git log $1 --format="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> %ai" >authortime &&
69 git log $1 --format="%cn <%ce> %ci" >committertime &&
7573cec5
PW
70 test_cmp authortime committertime
71}
72
16b0bb99 73test_expect_success '--committer-date-is-author-date works with apply backend' '
7573cec5
PW
74 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
75 git rebase --apply --committer-date-is-author-date HEAD^ &&
76 test_ctime_is_atime -1
77'
78
5f35edd9 79test_expect_success '--committer-date-is-author-date works with merge backend' '
7573cec5
PW
80 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
81 git rebase -m --committer-date-is-author-date HEAD^ &&
82 test_ctime_is_atime -1
83'
84
9d6b9df1
PW
85test_expect_success '--committer-date-is-author-date works when rewording' '
86 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
87 (
88 set_fake_editor &&
89 FAKE_COMMIT_MESSAGE=edited \
90 FAKE_LINES="reword 1" \
91 git rebase -i --committer-date-is-author-date HEAD^
92 ) &&
93 test_write_lines edited "" >expect &&
94 git log --format="%B" -1 >actual &&
95 test_cmp expect actual &&
96 test_ctime_is_atime -1
97'
98
5f35edd9 99test_expect_success '--committer-date-is-author-date works with rebase -r' '
7573cec5
PW
100 git checkout side &&
101 GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
102 git rebase -r --root --committer-date-is-author-date &&
103 test_ctime_is_atime
104'
105
5f35edd9 106test_expect_success '--committer-date-is-author-date works when forking merge' '
7573cec5
PW
107 git checkout side &&
108 GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
109 PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
110 --committer-date-is-author-date &&
111 test_ctime_is_atime
112'
113
114test_expect_success '--committer-date-is-author-date works when committing conflict resolution' '
115 git checkout commit2 &&
116 GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
117 test_must_fail git rebase -m --committer-date-is-author-date \
118 --onto HEAD^^ HEAD^ &&
119 echo resolved > foo &&
120 git add foo &&
121 git rebase --continue &&
122 test_ctime_is_atime -1
123'
124
a3894aad
PW
125# Checking for +0000 in the author date is sufficient since the
126# default timezone is UTC but the timezone used while committing is
127# +0530. The inverted logic in the grep is necessary to check all the
128# author dates in the file.
129test_atime_is_ignored () {
130 git log $1 --format=%ai >authortime &&
131 ! grep -v +0000 authortime
132}
133
27126692 134test_expect_success '--reset-author-date works with apply backend' '
a3894aad 135 git commit --amend --date="$GIT_AUTHOR_DATE" &&
27126692 136 git rebase --apply --reset-author-date HEAD^ &&
a3894aad
PW
137 test_atime_is_ignored -1
138'
139
27126692 140test_expect_success '--reset-author-date works with merge backend' '
a3894aad 141 git commit --amend --date="$GIT_AUTHOR_DATE" &&
27126692 142 git rebase --reset-author-date -m HEAD^ &&
a3894aad
PW
143 test_atime_is_ignored -1
144'
145
27126692
RA
146test_expect_success '--reset-author-date works after conflict resolution' '
147 test_must_fail git rebase --reset-author-date -m \
a3894aad
PW
148 --onto commit2^^ commit2^ commit2 &&
149 echo resolved >foo &&
150 git add foo &&
151 git rebase --continue &&
152 test_atime_is_ignored -1
153'
154
27126692 155test_expect_success '--reset-author-date works with rebase -r' '
a3894aad
PW
156 git checkout side &&
157 git merge --no-ff commit3 &&
27126692 158 git rebase -r --root --reset-author-date &&
a3894aad
PW
159 test_atime_is_ignored
160'
161
5f35edd9 162test_expect_success '--reset-author-date with --committer-date-is-author-date works' '
a3894aad 163 test_must_fail git rebase -m --committer-date-is-author-date \
27126692 164 --reset-author-date --onto commit2^^ commit2^ commit3 &&
a3894aad
PW
165 git checkout --theirs foo &&
166 git add foo &&
167 git rebase --continue &&
168 test_ctime_is_atime -2 &&
169 test_atime_is_ignored -2
170'
171
9d6b9df1
PW
172test_expect_success 'reset-author-date with --committer-date-is-author-date works when rewording' '
173 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
174 (
175 set_fake_editor &&
176 FAKE_COMMIT_MESSAGE=edited \
177 FAKE_LINES="reword 1" \
178 git rebase -i --committer-date-is-author-date \
179 --reset-author-date HEAD^
180 ) &&
181 test_write_lines edited "" >expect &&
182 git log --format="%B" -1 >actual &&
183 test_cmp expect actual &&
184 test_atime_is_ignored -1
185'
186
27126692 187test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
a3894aad
PW
188 GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
189 PATH="./test-bin:$PATH" git rebase -i --strategy=test \
27126692
RA
190 --reset-author-date \
191 --committer-date-is-author-date side side &&
a3894aad
PW
192 test_ctime_is_atime -1 &&
193 test_atime_is_ignored -1
194 '
195
27126692
RA
196test_expect_success '--ignore-date is an alias for --reset-author-date' '
197 git commit --amend --date="$GIT_AUTHOR_DATE" &&
198 git rebase --apply --ignore-date HEAD^ &&
199 git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" &&
200 git rebase -m --ignore-date HEAD^ &&
201 test_atime_is_ignored -2
202'
203
ef484add
RA
204# This must be the last test in this file
205test_expect_success '$EDITOR and friends are unchanged' '
206 test_editor_unchanged
207'
208
209test_done