Merge branch 'rr/rebase-sha1-by-string-query'
authorJunio C Hamano <gitster@pobox.com>
Mon, 24 Jun 2013 20:48:40 +0000 (13:48 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Jun 2013 20:48:40 +0000 (13:48 -0700)
Allow various commit objects to be given to "git rebase" by ':/look
for this string' syntax, e.g. "git rebase --onto ':/there'".

* rr/rebase-sha1-by-string-query:
rebase: use peel_committish() where appropriate
sh-setup: add new peel_committish() helper
t/rebase: add failing tests for a peculiar revision

1  2 
git-rebase.sh
t/t3400-rebase.sh
t/t3404-rebase-interactive.sh
diff --combined git-rebase.sh
index 2d5c2bd0fcf773367b892fbb993704e5f2089c64,6987b9b6db0b81ff4fa0ab8981c690c9a3765612..54015e3eaf5e091a387841d9a6e7cdd3085174f8
@@@ -84,8 -84,6 +84,8 @@@ keep_empty
  test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
  
  read_basic_state () {
 +      test -f "$state_dir/head-name" &&
 +      test -f "$state_dir/onto" &&
        head_name=$(cat "$state_dir"/head-name) &&
        onto=$(cat "$state_dir"/onto) &&
        # We always write to orig-head, but interactive rebase used to write to
@@@ -436,7 -434,7 +436,7 @@@ the
                shift
                ;;
        esac
-       upstream=`git rev-parse --verify "${upstream_name}^0"` ||
+       upstream=$(peel_committish "${upstream_name}") ||
        die "$(eval_gettext "invalid upstream \$upstream_name")"
        upstream_arg="$upstream_name"
  else
@@@ -472,7 -470,7 +472,7 @@@ case "$onto_name" i
        fi
        ;;
  *)
-       onto=$(git rev-parse --verify "${onto_name}^0") ||
+       onto=$(peel_committish "$onto_name") ||
        die "$(eval_gettext "Does not point to a valid commit: \$onto_name")"
        ;;
  esac
@@@ -547,7 -545,6 +547,7 @@@ the
                # Lazily switch to the target branch if needed...
                test -z "$switch_to" || git checkout "$switch_to" --
                say "$(eval_gettext "Current branch \$branch_name is up to date.")"
 +              finish_rebase
                exit 0
        else
                say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
@@@ -580,7 -577,6 +580,7 @@@ if test "$mb" = "$orig_head
  then
        say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
        move_to_original_branch
 +      finish_rebase
        exit 0
  fi
  
diff --combined t/t3400-rebase.sh
index ff86725b7beba19c138b33bd874d31fd540c026e,cbca71ed56bd4443cbfc1f4842eb589b6beeae16..ebf93b0695dfac37fc276e1f07377d858eb3e1da
@@@ -40,6 -40,13 +40,6 @@@ test_expect_success 'prepare repositor
        echo Side >>C &&
        git add C &&
        git commit -m "Add C" &&
 -      git checkout -b nonlinear my-topic-branch &&
 -      echo Edit >>B &&
 -      git add B &&
 -      git commit -m "Modify B" &&
 -      git merge side &&
 -      git checkout -b upstream-merged-nonlinear &&
 -      git merge master &&
        git checkout -f my-topic-branch &&
        git tag topic
  '
@@@ -59,6 -66,39 +59,17 @@@ test_expect_success 'rebase against mas
        git rebase master
  '
  
 -test_expect_success 'rebase against master twice' '
 -      git rebase master >out &&
 -      test_i18ngrep "Current branch my-topic-branch is up to date" out
 -'
 -
 -test_expect_success 'rebase against master twice with --force' '
 -      git rebase --force-rebase master >out &&
 -      test_i18ngrep "Current branch my-topic-branch is up to date, rebase forced" out
 -'
 -
 -test_expect_success 'rebase against master twice from another branch' '
 -      git checkout my-topic-branch^ &&
 -      git rebase master my-topic-branch >out &&
 -      test_i18ngrep "Current branch my-topic-branch is up to date" out
 -'
 -
 -test_expect_success 'rebase fast-forward to master' '
 -      git checkout my-topic-branch^ &&
 -      git rebase my-topic-branch >out &&
 -      test_i18ngrep "Fast-forwarded HEAD to my-topic-branch" out
 -'
 -
+ test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
+       test_when_finished "git branch -D torebase" &&
+       git checkout -b torebase my-topic-branch^ &&
+       upstream=$(git rev-parse ":/Add B") &&
+       onto=$(git rev-parse ":/Add A") &&
+       git rebase --onto $onto $upstream &&
+       git reset --hard my-topic-branch^ &&
+       git rebase --onto ":/Add A" ":/Add B" &&
+       git checkout my-topic-branch
+ '
  test_expect_success 'the rebase operation should not have destroyed author information' '
        ! (git log | grep "Author:" | grep "<>")
  '
@@@ -77,9 -117,31 +88,9 @@@ test_expect_success 'rebase from ambigu
        git rebase master
  '
  
 -test_expect_success 'rebase after merge master' '
 -      git checkout --detach refs/tags/topic &&
 -      git branch -D topic &&
 -      git reset --hard topic &&
 -      git merge master &&
 -      git rebase master &&
 -      ! (git show | grep "^Merge:")
 -'
 -
 -test_expect_success 'rebase of history with merges is linearized' '
 -      git checkout nonlinear &&
 -      test 4 = $(git rev-list master.. | wc -l) &&
 -      git rebase master &&
 -      test 3 = $(git rev-list master.. | wc -l)
 -'
 -
 -test_expect_success 'rebase of history with merges after upstream merge is linearized' '
 -      git checkout upstream-merged-nonlinear &&
 -      test 5 = $(git rev-list master.. | wc -l) &&
 -      git rebase master &&
 -      test 3 = $(git rev-list master.. | wc -l)
 -'
 -
  test_expect_success 'rebase a single mode change' '
        git checkout master &&
 +      git branch -D topic &&
        echo 1 >X &&
        git add X &&
        test_tick &&
@@@ -134,7 -196,7 +145,7 @@@ test_expect_success 'default to @{upstr
  test_expect_success 'rebase -q is quiet' '
        git checkout -b quiet topic &&
        git rebase -q master >output.out 2>&1 &&
 -      test ! -s output.out
 +      test_must_be_empty output.out
  '
  
  test_expect_success 'Rebase a commit that sprinkles CRs in' '
index 0d3c57340ebf1de3f8aff05c15e05df81b173b41,86917d172f78ca4b5edd5dfe1334d1f1100fe36b..d6b414377306de88e8e294dd5eaadfcb3a234ec2
@@@ -477,11 -477,19 +477,11 @@@ test_expect_success 'interrupted squas
        test $one = $(git rev-parse HEAD~2)
  '
  
 -test_expect_success 'ignore patch if in upstream' '
 -      HEAD=$(git rev-parse HEAD) &&
 -      git checkout -b has-cherry-picked HEAD^ &&
 +test_expect_success '--continue tries to commit, even for "edit"' '
        echo unrelated > file7 &&
        git add file7 &&
        test_tick &&
        git commit -m "unrelated change" &&
 -      git cherry-pick $HEAD &&
 -      EXPECT_COUNT=1 git rebase -i $HEAD &&
 -      test $HEAD = $(git rev-parse HEAD^)
 -'
 -
 -test_expect_success '--continue tries to commit, even for "edit"' '
        parent=$(git rev-parse HEAD^) &&
        test_tick &&
        FAKE_LINES="edit 1" git rebase -i HEAD^ &&
@@@ -939,4 -947,15 +939,15 @@@ test_expect_success 'rebase -i respect
        test B = $(git cat-file commit HEAD^ | sed -ne \$p)
  '
  
+ test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
+       test_when_finished "git branch -D torebase" &&
+       git checkout -b torebase branch1 &&
+       upstream=$(git rev-parse ":/J") &&
+       onto=$(git rev-parse ":/A") &&
+       git rebase --onto $onto $upstream &&
+       git reset --hard branch1 &&
+       git rebase --onto ":/A" ":/J" &&
+       git checkout branch1
+ '
  test_done