Merge branch 'aw/rebase-i-edit-todo'
authorJunio C Hamano <gitster@pobox.com>
Sun, 30 Sep 2012 05:28:12 +0000 (22:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 30 Sep 2012 05:28:12 +0000 (22:28 -0700)
Teach an option to edit the insn sheet to "git rebase -i".

* aw/rebase-i-edit-todo:
rebase -i: suggest using --edit-todo to fix an unknown instruction
rebase -i: Add tests for "--edit-todo"
rebase -i: Teach "--edit-todo" action
rebase -i: Refactor help messages for todo file
rebase usage: subcommands can not be combined with -i

1  2 
git-rebase--interactive.sh
t/t3404-rebase-interactive.sh
index 56707d7a279274d4086b3eb3f1d1810f66fa8aed,4b2ef11e59d465cf745714ebb917525eb74fe4e0..44901d53c43d972e03a71bfbe0b769f2e8f22d7b
@@@ -115,6 -115,23 +115,23 @@@ mark_action_done () 
        fi
  }
  
+ append_todo_help () {
+       cat >> "$todo" << EOF
+ #
+ # Commands:
+ #  p, pick = use commit
+ #  r, reword = use commit, but edit the commit message
+ #  e, edit = use commit, but stop for amending
+ #  s, squash = use commit, but meld into previous commit
+ #  f, fixup = like "squash", but discard this commit's log message
+ #  x, exec = run command (the rest of the line) using shell
+ #
+ # These lines can be re-ordered; they are executed from top to bottom.
+ #
+ # If you remove a line here THAT COMMIT WILL BE LOST.
+ EOF
+ }
  make_patch () {
        sha1_and_parents="$(git rev-list --parents -1 "$1")"
        case "$sha1_and_parents" in
@@@ -544,10 -561,6 +561,10 @@@ do_next () 
                        warn
                        warn "  git rebase --continue"
                        warn
 +                      if test $status -eq 127         # command not found
 +                      then
 +                              status=1
 +                      fi
                        exit "$status"
                elif test "$dirty" = t
                then
                ;;
        *)
                warn "Unknown command: $command $sha1 $rest"
+               fixtodo="Please fix this using 'git rebase --edit-todo'."
                if git rev-parse --verify -q "$sha1" >/dev/null
                then
-                       die_with_patch $sha1 "Please fix this in the file $todo."
+                       die_with_patch $sha1 "$fixtodo"
                else
-                       die "Please fix this in the file $todo."
+                       die "$fixtodo"
                fi
                ;;
        esac
@@@ -779,6 -793,23 +797,23 @@@ skip
  
        do_rest
        ;;
+ edit-todo)
+       sed -e '/^#/d' < "$todo" > "$todo".new
+       mv -f "$todo".new "$todo"
+       append_todo_help
+       cat >> "$todo" << EOF
+ #
+ # You are editing the todo file of an ongoing interactive rebase.
+ # To continue rebase after editing, run:
+ #     git rebase --continue
+ #
+ EOF
+       git_sequence_editor "$todo" ||
+               die "Could not execute editor"
+       exit
+       ;;
  esac
  
  git var GIT_COMMITTER_IDENT >/dev/null ||
@@@ -905,18 -936,10 +940,10 @@@ test -n "$cmd" && add_exec_commands "$t
  cat >> "$todo" << EOF
  
  # Rebase $shortrevisions onto $shortonto
+ EOF
+ append_todo_help
+ cat >> "$todo" << EOF
  #
- # Commands:
- #  p, pick = use commit
- #  r, reword = use commit, but edit the commit message
- #  e, edit = use commit, but stop for amending
- #  s, squash = use commit, but meld into previous commit
- #  f, fixup = like "squash", but discard this commit's log message
- #  x, exec = run command (the rest of the line) using shell
- #
- # These lines can be re-ordered; they are executed from top to bottom.
- #
- # If you remove a line here THAT COMMIT WILL BE LOST.
  # However, if you remove everything, the rebase will be aborted.
  #
  EOF
index 7a7176088bc7c7e8a75a70538871a438c0667503,6eafb634656ee67bbc3fc8869a5a4ee6d647112b..32fdc9938e1dc29d9a1c6c1dd54379ee33644561
@@@ -118,17 -118,6 +118,17 @@@ test_expect_success 'rebase -i with th
        git rebase --continue
  '
  
 +test_expect_success 'rebase -i with exec of inexistent command' '
 +      git checkout master &&
 +      test_when_finished "git rebase --abort" &&
 +      (
 +      FAKE_LINES="exec_this-command-does-not-exist 1" &&
 +      export FAKE_LINES &&
 +      test_must_fail git rebase -i HEAD^ >actual 2>&1
 +      ) &&
 +      ! grep "Maybe git-rebase is broken" actual
 +'
 +
  test_expect_success 'no changes are a nop' '
        git checkout branch2 &&
        git rebase -i F &&
@@@ -922,4 -911,22 +922,22 @@@ test_expect_success 'rebase -i --root f
        test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
  '
  
+ test_expect_success 'rebase --edit-todo does not works on non-interactive rebase' '
+       git reset --hard &&
+       git checkout conflict-branch &&
+       test_must_fail git rebase --onto HEAD~2 HEAD~ &&
+       test_must_fail git rebase --edit-todo &&
+       git rebase --abort
+ '
+ test_expect_success 'rebase --edit-todo can be used to modify todo' '
+       git reset --hard &&
+       git checkout no-conflict-branch^0 &&
+       FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
+       FAKE_LINES="2 1" git rebase --edit-todo &&
+       git rebase --continue
+       test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
+       test L = $(git cat-file commit HEAD | sed -ne \$p)
+ '
  test_done