3 # Copyright (c) 2019 Rohit Ashiwal
6 test_description='tests to ensure compatibility between am and interactive backends'
10 . "$TEST_DIRECTORY"/lib-rebase.sh
12 GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
13 export GIT_AUTHOR_DATE
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 &&
22 git commit -m "add file" &&
24 test_write_lines "line 1" "new line 2" "line 3" >file &&
25 git commit -am "update file" &&
27 test_commit commit1 foo foo1 &&
28 test_commit commit2 foo foo2 &&
29 test_commit commit3 foo foo3 &&
31 git checkout --orphan master &&
33 test_write_lines "line 1" " line 2" "line 3" >file &&
34 git commit -am "add file" &&
38 write_script test-bin/git-merge-test <<-\EOF
39 exec git merge-recursive "$@"
43 test_expect_success '--ignore-whitespace works with apply backend' '
44 test_must_fail git rebase --apply main side &&
46 git rebase --apply --ignore-whitespace main side &&
47 git diff --exit-code side
50 test_expect_success '--ignore-whitespace works with merge backend' '
51 test_must_fail git rebase --merge main side &&
53 git rebase --merge --ignore-whitespace main side &&
54 git diff --exit-code side
57 test_expect_success '--ignore-whitespace is remembered when continuing' '
60 FAKE_LINES="break 1" git rebase -i --ignore-whitespace \
64 git diff --exit-code side
67 test_ctime_is_atime () {
68 git log $1 --format="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> %ai" >authortime &&
69 git log $1 --format="%cn <%ce> %ci" >committertime &&
70 test_cmp authortime committertime
73 test_expect_success '--committer-date-is-author-date works with apply backend' '
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
79 test_expect_success '--committer-date-is-author-date works with merge backend' '
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
85 test_expect_success '--committer-date-is-author-date works with rebase -r' '
87 GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
88 git rebase -r --root --committer-date-is-author-date &&
92 test_expect_success '--committer-date-is-author-date works when forking merge' '
94 GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
95 PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
96 --committer-date-is-author-date &&
100 test_expect_success '--committer-date-is-author-date works when committing conflict resolution' '
101 git checkout commit2 &&
102 GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
103 test_must_fail git rebase -m --committer-date-is-author-date \
104 --onto HEAD^^ HEAD^ &&
105 echo resolved > foo &&
107 git rebase --continue &&
108 test_ctime_is_atime -1
111 # Checking for +0000 in the author date is sufficient since the
112 # default timezone is UTC but the timezone used while committing is
113 # +0530. The inverted logic in the grep is necessary to check all the
114 # author dates in the file.
115 test_atime_is_ignored () {
116 git log $1 --format=%ai >authortime &&
117 ! grep -v +0000 authortime
120 test_expect_success '--reset-author-date works with apply backend' '
121 git commit --amend --date="$GIT_AUTHOR_DATE" &&
122 git rebase --apply --reset-author-date HEAD^ &&
123 test_atime_is_ignored -1
126 test_expect_success '--reset-author-date works with merge backend' '
127 git commit --amend --date="$GIT_AUTHOR_DATE" &&
128 git rebase --reset-author-date -m HEAD^ &&
129 test_atime_is_ignored -1
132 test_expect_success '--reset-author-date works after conflict resolution' '
133 test_must_fail git rebase --reset-author-date -m \
134 --onto commit2^^ commit2^ commit2 &&
135 echo resolved >foo &&
137 git rebase --continue &&
138 test_atime_is_ignored -1
141 test_expect_success '--reset-author-date works with rebase -r' '
143 git merge --no-ff commit3 &&
144 git rebase -r --root --reset-author-date &&
145 test_atime_is_ignored
148 test_expect_success '--reset-author-date with --committer-date-is-author-date works' '
149 test_must_fail git rebase -m --committer-date-is-author-date \
150 --reset-author-date --onto commit2^^ commit2^ commit3 &&
151 git checkout --theirs foo &&
153 git rebase --continue &&
154 test_ctime_is_atime -2 &&
155 test_atime_is_ignored -2
158 test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
159 GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
160 PATH="./test-bin:$PATH" git rebase -i --strategy=test \
161 --reset-author-date \
162 --committer-date-is-author-date side side &&
163 test_ctime_is_atime -1 &&
164 test_atime_is_ignored -1
167 test_expect_success '--ignore-date is an alias for --reset-author-date' '
168 git commit --amend --date="$GIT_AUTHOR_DATE" &&
169 git rebase --apply --ignore-date HEAD^ &&
170 git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" &&
171 git rebase -m --ignore-date HEAD^ &&
172 test_atime_is_ignored -2
175 # This must be the last test in this file
176 test_expect_success '$EDITOR and friends are unchanged' '
177 test_editor_unchanged