]> rtime.felk.cvut.cz Git - git.git/commitdiff
Merge branch 'do/rebase-i-arbitrary'
authorJunio C Hamano <gitster@pobox.com>
Sat, 3 Apr 2010 19:28:38 +0000 (12:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 3 Apr 2010 19:28:38 +0000 (12:28 -0700)
* do/rebase-i-arbitrary:
  rebase--interactive: don't require what's rebased to be a branch

Conflicts:
t/t3404-rebase-interactive.sh

1  2 
git-rebase--interactive.sh
t/t3404-rebase-interactive.sh

index 1d116bfae2175891905d40ba4b55b331fba63372,d047dcb3e4c4eddfc48738dcad7397af1e16be57..2ff211cbaa928275857577535f02ae92cb407f2f
@@@ -96,13 -96,6 +96,13 @@@ AUTHOR_SCRIPT="$DOTEST"/author-scrip
  # command is processed, this file is deleted.
  AMEND="$DOTEST"/amend
  
 +# For the post-rewrite hook, we make a list of rewritten commits and
 +# their new sha1s.  The rewritten-pending list keeps the sha1s of
 +# commits that have been processed, but not committed yet,
 +# e.g. because they are waiting for a 'squash' command.
 +REWRITTEN_LIST="$DOTEST"/rewritten-list
 +REWRITTEN_PENDING="$DOTEST"/rewritten-pending
 +
  PRESERVE_MERGES=
  STRATEGY=
  ONTO=
@@@ -205,7 -198,6 +205,7 @@@ make_patch () 
  }
  
  die_with_patch () {
 +      echo "$1" > "$DOTEST"/stopped-sha
        make_patch "$1"
        git rerere
        die "$2"
@@@ -230,8 -222,8 +230,8 @@@ do_with_author () 
  }
  
  pick_one () {
 -      no_ff=
 -      case "$1" in -n) sha1=$2; no_ff=t ;; *) sha1=$1 ;; esac
 +      ff=--ff
 +      case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
        output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
        test -d "$REWRITTEN" &&
                pick_one_preserving_merges "$@" && return
                output git cherry-pick "$@"
                return
        fi
 -      parent_sha1=$(git rev-parse --verify $sha1^) ||
 -              die "Could not get the parent of $sha1"
 -      current_sha1=$(git rev-parse --verify HEAD)
 -      if test -z "$no_ff" && test "$current_sha1" = "$parent_sha1"
 -      then
 -              output git reset --hard $sha1
 -              output warn Fast-forward to $(git rev-parse --short $sha1)
 -      else
 -              output git cherry-pick "$@"
 -      fi
 +      output git cherry-pick $ff "$@"
  }
  
  pick_one_preserving_merges () {
                                printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
                                die_with_patch $sha1 "Error redoing merge $sha1"
                        fi
 +                      echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST"
                        ;;
                *)
                        output git cherry-pick "$@" ||
@@@ -425,26 -425,6 +425,26 @@@ die_failed_squash() 
        die_with_patch $1 ""
  }
  
 +flush_rewritten_pending() {
 +      test -s "$REWRITTEN_PENDING" || return
 +      newsha1="$(git rev-parse HEAD^0)"
 +      sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST"
 +      rm -f "$REWRITTEN_PENDING"
 +}
 +
 +record_in_rewritten() {
 +      oldsha1="$(git rev-parse $1)"
 +      echo "$oldsha1" >> "$REWRITTEN_PENDING"
 +
 +      case "$(peek_next_command)" in
 +          squash|s|fixup|f)
 +              ;;
 +          *)
 +              flush_rewritten_pending
 +              ;;
 +      esac
 +}
 +
  do_next () {
        rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit
        read command sha1 rest < "$TODO"
                mark_action_done
                pick_one $sha1 ||
                        die_with_patch $sha1 "Could not apply $sha1... $rest"
 +              record_in_rewritten $sha1
                ;;
        reword|r)
                comment_for_reflog reword
                mark_action_done
                pick_one $sha1 ||
                        die_with_patch $sha1 "Could not apply $sha1... $rest"
 -              git commit --amend
 +              git commit --amend --no-post-rewrite
 +              record_in_rewritten $sha1
                ;;
        edit|e)
                comment_for_reflog edit
                mark_action_done
                pick_one $sha1 ||
                        die_with_patch $sha1 "Could not apply $sha1... $rest"
 +              echo "$sha1" > "$DOTEST"/stopped-sha
                make_patch $sha1
                git rev-parse --verify HEAD > "$AMEND"
                warn "Stopped at $sha1... $rest"
                        rm -f "$SQUASH_MSG" "$FIXUP_MSG"
                        ;;
                esac
 +              record_in_rewritten $sha1
                ;;
        *)
                warn "Unknown command: $command $sha1 $rest"
                test ! -f "$DOTEST"/verbose ||
                        git diff-tree --stat $(cat "$DOTEST"/head)..HEAD
        } &&
 +      {
 +              git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" ||
 +              true # we don't care if this copying failed
 +      } &&
 +      if test -x "$GIT_DIR"/hooks/post-rewrite &&
 +              test -s "$REWRITTEN_LIST"; then
 +              "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
 +              true # we don't care if this hook failed
 +      fi &&
        rm -rf "$DOTEST" &&
        git gc --auto &&
        warn "Successfully rebased and updated $HEADNAME."
@@@ -604,12 -571,7 +604,12 @@@ skip_unnecessary_picks () 
                esac
                echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
        done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
 -      mv -f "$TODO".new "$TODO" ||
 +      mv -f "$TODO".new "$TODO" &&
 +      case "$(peek_next_command)" in
 +      squash|s|fixup|f)
 +              record_in_rewritten "$ONTO"
 +              ;;
 +      esac ||
        die "Could not skip unnecessary pick commands"
  }
  
@@@ -725,8 -687,6 +725,8 @@@ first and then run 'git rebase --contin
                        }
                fi
  
 +              record_in_rewritten "$(cat "$DOTEST"/stopped-sha)"
 +
                require_clean_work_tree
                do_rest
                ;;
  
                if test ! -z "$1"
                then
-                       output git show-ref --verify --quiet "refs/heads/$1" ||
-                               die "Invalid branchname: $1"
                        output git checkout "$1" ||
                                die "Could not checkout $1"
                fi
index 19668c2c9206c5dfe63a5992bc7d011a9cdb4083,05708c2462b1b2d90113553065bbbe3dad53cc9c..b0b43c6d329cacf24fd9ea6d69320e13d34b154c
@@@ -553,28 -553,13 +553,37 @@@ test_expect_success 'reword' 
        git show HEAD~2 | grep "C changed"
  '
  
 +test_expect_success 'rebase -i can copy notes' '
 +      git config notes.rewrite.rebase true &&
 +      git config notes.rewriteRef "refs/notes/*" &&
 +      test_commit n1 &&
 +      test_commit n2 &&
 +      test_commit n3 &&
 +      git notes add -m"a note" n3 &&
 +      git rebase --onto n1 n2 &&
 +      test "a note" = "$(git notes show HEAD)"
 +'
 +
 +cat >expect <<EOF
 +an earlier note
 +a note
 +EOF
 +
 +test_expect_success 'rebase -i can copy notes over a fixup' '
 +      git reset --hard n3 &&
 +      git notes add -m"an earlier note" n2 &&
 +      GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
 +      git notes show > output &&
 +      test_cmp expect output
 +'
 +
+ test_expect_success 'rebase while detaching HEAD' '
+       git symbolic-ref HEAD &&
+       grandparent=$(git rev-parse HEAD~2) &&
+       test_tick &&
+       FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
+       test $grandparent = $(git rev-parse HEAD~2) &&
+       test_must_fail git symbolic-ref HEAD
+ '
  test_done