@matheusbsbs / matheus-bagliano / commits / 18640d991b
Fork 0

rebase -i: handle --continue more like non-interactive rebase

Non-interactive rebase requires the working tree to be clean, but applies what is in the index without requiring the user to do it herself. Imitate that, but (since we are interactive, after all) fire up an editor with the commit message. It also fixes a subtle bug: a forgotten "continue" was removed, which led to an infinite loop when continuing without remaining patches. Both issues noticed by Frank Lichtenheld. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 8, 2007 at 03:01 UTC 18640d991bde7e081fb851cea5114c09472b188f
2 files changed +32 -10
git-rebase--interactive.sh
+17 -9
@@ -59,6 +59,10 @@ make_patch () {
59 }
60
61 die_with_patch () {
62 + test -f "$DOTEST"/message ||
63 + git cat-file commit $sha1 | sed "1,/^$/d" > "$DOTEST"/message
64 + test -f "$DOTEST"/author-script ||
65 + get_author_ident_from_commit $sha1 > "$DOTEST"/author-script
66 make_patch "$1"
67 die "$2"
68 }
@@ -140,10 +144,7 @@ pick_one_preserving_merges () {
144 if ! git merge $STRATEGY -m "$msg" $new_parents
145 then
146 echo "$msg" > "$GIT_DIR"/MERGE_MSG
143 - warn Error redoing merge $sha1
144 - warn
145 - warn After fixup, please use
146 - die "$author_script git commit"
147 + die Error redoing merge $sha1
148 fi
149 ;;
150 *)
@@ -154,11 +155,12 @@ pick_one_preserving_merges () {
155 }
156
157 do_next () {
158 + test -f "$DOTEST"/message && rm "$DOTEST"/message
159 + test -f "$DOTEST"/author-script && rm "$DOTEST"/author-script
160 read command sha1 rest < "$TODO"
161 case "$command" in
162 \#|'')
163 mark_action_done
161 - continue
164 ;;
165 pick)
166 comment_for_reflog pick
@@ -201,6 +203,7 @@ do_next () {
203 git cat-file commit $sha1 | sed -e '1,/^$/d' >> "$MSG"
204 git reset --soft HEAD^
205 author_script=$(get_author_ident_from_commit $sha1)
206 + echo "$author_script" > "$DOTEST"/author-script
207 case $failed in
208 f)
209 # This is like --amend, but with a different message
@@ -212,10 +215,6 @@ do_next () {
215 cp "$MSG" "$GIT_DIR"/MERGE_MSG
216 warn
217 warn "Could not apply $sha1... $rest"
215 - warn "After you fixed that, commit the result with"
216 - warn
217 - warn " $(echo $author_script | tr '\012' ' ') \\"
218 - warn " git commit -F \"$GIT_DIR\"/MERGE_MSG -e"
218 die_with_patch $sha1 ""
219 esac
220 ;;
@@ -265,6 +264,15 @@ do
264
265 test -d "$DOTEST" || die "No interactive rebase running"
266
267 + # commit if necessary
268 + git rev-parse --verify HEAD > /dev/null &&
269 + git update-index --refresh &&
270 + git diff-files --quiet &&
271 + ! git diff-index --cached --quiet HEAD &&
272 + . "$DOTEST"/author-script &&
273 + export GIT_AUTHOR_NAME GIT_AUTHOR_NAME GIT_AUTHOR_DATE &&
274 + git commit -F "$DOTEST"/message -e
275 +
276 require_clean_work_tree
277 do_rest
278 ;;
t/t3404-rebase-interactive.sh
+15 -1
@@ -63,7 +63,10 @@ test_expect_success 'setup' '
63
64 cat > fake-editor.sh << EOF
65 #!/bin/sh
66 -test "\$1" = .git/COMMIT_EDITMSG && exit
66 +test "\$1" = .git/COMMIT_EDITMSG && {
67 + test -z "\$FAKE_COMMIT_MESSAGE" || echo "\$FAKE_COMMIT_MESSAGE" > "\$1"
68 + exit
69 +}
70 test -z "\$FAKE_LINES" && exit
71 grep -v "^#" < "\$1" > "\$1".tmp
72 rm "\$1"
@@ -181,6 +184,7 @@ test_expect_success 'preserve merges with -p' '
184 echo C > file1 &&
185 test_tick &&
186 git commit -m K file1 &&
187 + test_tick &&
188 git rebase -i -p --onto branch1 master &&
189 test $(git rev-parse HEAD^^2) = $(git rev-parse to-be-preserved) &&
190 test $(git rev-parse HEAD~3) = $(git rev-parse branch1) &&
@@ -188,4 +192,14 @@ test_expect_success 'preserve merges with -p' '
192 test $(git show HEAD~2:file1) = B
193 '
194
195 +test_expect_success '--continue tries to commit' '
196 + test_tick &&
197 + ! git rebase -i --onto new-branch1 HEAD^ &&
198 + echo resolved > file1 &&
199 + git add file1 &&
200 + FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
201 + test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
202 + git show HEAD | grep chouette
203 +'
204 +
205 test_done