The eleventh batch
[git/gitster.git] / t / t3436-rebase-more-options.sh
blob4d9744e5fc7ade70fc4cf2b7a594d1b0513e0f58
1 #!/bin/sh
3 # Copyright (c) 2019 Rohit Ashiwal
6 test_description='tests to ensure compatibility between am and interactive backends'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 . "$TEST_DIRECTORY"/lib-rebase.sh
13 GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
14 export GIT_AUTHOR_DATE
16 # This is a special case in which both am and interactive backends
17 # provide the same output. It was done intentionally because
18 # both the backends fall short of optimal behaviour.
19 test_expect_success 'setup' '
20 git checkout -b topic &&
21 test_write_lines "line 1" " line 2" "line 3" >file &&
22 git add file &&
23 git commit -m "add file" &&
25 test_write_lines "line 1" "new line 2" "line 3" >file &&
26 git commit -am "update file" &&
27 git tag side &&
28 test_commit commit1 foo foo1 &&
29 test_commit commit2 foo foo2 &&
30 test_commit commit3 foo foo3 &&
32 git checkout --orphan main &&
33 rm foo &&
34 test_write_lines "line 1" " line 2" "line 3" >file &&
35 git commit -am "add file" &&
36 git tag main &&
38 mkdir test-bin &&
39 write_script test-bin/git-merge-test <<-\EOF
40 exec git merge-recursive "$@"
41 EOF
44 test_expect_success '--ignore-whitespace works with apply backend' '
45 test_must_fail git rebase --apply main side &&
46 git rebase --abort &&
47 git rebase --apply --ignore-whitespace main side &&
48 git diff --exit-code side
51 test_expect_success '--ignore-whitespace works with merge backend' '
52 test_must_fail git rebase --merge main side &&
53 git rebase --abort &&
54 git rebase --merge --ignore-whitespace main side &&
55 git diff --exit-code side
58 test_expect_success '--ignore-whitespace is remembered when continuing' '
60 set_fake_editor &&
61 FAKE_LINES="break 1" git rebase -i --ignore-whitespace \
62 main side &&
63 git rebase --continue
64 ) &&
65 git diff --exit-code side
68 test_ctime_is_atime () {
69 git log $1 --format="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> %ai" >authortime &&
70 git log $1 --format="%cn <%ce> %ci" >committertime &&
71 test_cmp authortime committertime
74 test_expect_success '--committer-date-is-author-date works with apply backend' '
75 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
76 git rebase --apply --committer-date-is-author-date HEAD^ &&
77 test_ctime_is_atime -1
80 test_expect_success '--committer-date-is-author-date works with merge backend' '
81 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
82 git rebase -m --committer-date-is-author-date HEAD^ &&
83 test_ctime_is_atime -1
86 test_expect_success '--committer-date-is-author-date works when rewording' '
87 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
89 set_fake_editor &&
90 FAKE_COMMIT_MESSAGE=edited \
91 FAKE_LINES="reword 1" \
92 git rebase -i --committer-date-is-author-date HEAD^
93 ) &&
94 test_write_lines edited "" >expect &&
95 git log --format="%B" -1 >actual &&
96 test_cmp expect actual &&
97 test_ctime_is_atime -1
100 test_expect_success '--committer-date-is-author-date works with rebase -r' '
101 git checkout side &&
102 GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
103 git rebase -r --root --committer-date-is-author-date &&
104 test_ctime_is_atime
107 test_expect_success '--committer-date-is-author-date works when forking merge' '
108 git checkout side &&
109 GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
110 PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
111 --committer-date-is-author-date &&
112 test_ctime_is_atime
115 test_expect_success '--committer-date-is-author-date works when committing conflict resolution' '
116 git checkout commit2 &&
117 GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
118 test_must_fail git rebase -m --committer-date-is-author-date \
119 --onto HEAD^^ HEAD^ &&
120 echo resolved > foo &&
121 git add foo &&
122 git rebase --continue &&
123 test_ctime_is_atime -1
126 # Checking for +0000 in the author date is sufficient since the
127 # default timezone is UTC but the timezone used while committing is
128 # +0530. The inverted logic in the grep is necessary to check all the
129 # author dates in the file.
130 test_atime_is_ignored () {
131 git log $1 --format=%ai >authortime &&
132 ! grep -v +0000 authortime
135 test_expect_success '--reset-author-date works with apply backend' '
136 git commit --amend --date="$GIT_AUTHOR_DATE" &&
137 git rebase --apply --reset-author-date HEAD^ &&
138 test_atime_is_ignored -1
141 test_expect_success '--reset-author-date works with merge backend' '
142 git commit --amend --date="$GIT_AUTHOR_DATE" &&
143 git rebase --reset-author-date -m HEAD^ &&
144 test_atime_is_ignored -1
147 test_expect_success '--reset-author-date works after conflict resolution' '
148 test_must_fail git rebase --reset-author-date -m \
149 --onto commit2^^ commit2^ commit2 &&
150 echo resolved >foo &&
151 git add foo &&
152 git rebase --continue &&
153 test_atime_is_ignored -1
156 test_expect_success '--reset-author-date works with rebase -r' '
157 git checkout side &&
158 git merge --no-ff commit3 &&
159 git rebase -r --root --reset-author-date &&
160 test_atime_is_ignored
163 test_expect_success '--reset-author-date with --committer-date-is-author-date works' '
164 test_must_fail git rebase -m --committer-date-is-author-date \
165 --reset-author-date --onto commit2^^ commit2^ commit3 &&
166 git checkout --theirs foo &&
167 git add foo &&
168 git rebase --continue &&
169 test_ctime_is_atime -2 &&
170 test_atime_is_ignored -2
173 test_expect_success 'reset-author-date with --committer-date-is-author-date works when rewording' '
174 GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
176 set_fake_editor &&
177 FAKE_COMMIT_MESSAGE=edited \
178 FAKE_LINES="reword 1" \
179 git rebase -i --committer-date-is-author-date \
180 --reset-author-date HEAD^
181 ) &&
182 test_write_lines edited "" >expect &&
183 git log --format="%B" -1 >actual &&
184 test_cmp expect actual &&
185 test_atime_is_ignored -1
188 test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
189 GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
190 PATH="./test-bin:$PATH" git rebase -i --strategy=test \
191 --reset-author-date \
192 --committer-date-is-author-date side side &&
193 test_ctime_is_atime -1 &&
194 test_atime_is_ignored -1
197 test_expect_success '--ignore-date is an alias for --reset-author-date' '
198 git commit --amend --date="$GIT_AUTHOR_DATE" &&
199 git rebase --apply --ignore-date HEAD^ &&
200 git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" &&
201 git rebase -m --ignore-date HEAD^ &&
202 test_atime_is_ignored -2
205 # This must be the last test in this file
206 test_expect_success '$EDITOR and friends are unchanged' '
207 test_editor_unchanged
210 test_done