Merge branch 'mz/rebase-no-mbox'
authorJunio C Hamano <gitster@pobox.com>
Fri, 13 Jul 2012 22:36:31 +0000 (15:36 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 13 Jul 2012 22:36:31 +0000 (15:36 -0700)
Teach "am --rebasing" codepath to grab authorship, log message and
the patch text directly out of existing commits. This will help
rebasing commits that have confusing "diff" output in their log
messages.

* mz/rebase-no-mbox:
am: don't call mailinfo if $rebasing
am --rebasing: get patch body from commit, not from mailbox
rebase --root: print usage on too many args
rebase: don't source git-sh-setup twice

git-am.sh
git-rebase--am.sh
git-rebase--interactive.sh
git-rebase--merge.sh
git-rebase.sh
t/t3405-rebase-malformed.sh
t/t3412-rebase-root.sh
index f8b7a0cb602d2d2425f68f8c27338cc003b70f6b..b6a530018e18527efc8ed788e815b380d0206787 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -260,7 +260,7 @@ check_patch_format () {
 split_patches () {
        case "$patch_format" in
        mbox)
-               if test -n "$rebasing" || test t = "$keepcr"
+               if test t = "$keepcr"
                then
                    keep_cr=--keep-cr
                else
@@ -413,7 +413,7 @@ do
        --abort)
                abort=t ;;
        --rebasing)
-               rebasing=t threeway=t keep=t scissors=f no_inbody_headers=t ;;
+               rebasing=t threeway=t ;;
        -d|--dotest)
                die "$(gettext "-d option is no longer supported.  Do not use.")"
                ;;
@@ -658,32 +658,34 @@ do
        # by the user, or the user can tell us to do so by --resolved flag.
        case "$resume" in
        '')
-               git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
-                       <"$dotest/$msgnum" >"$dotest/info" ||
-                       stop_here $this
-
-               # skip pine's internal folder data
-               sane_grep '^Author: Mail System Internal Data$' \
-                       <"$dotest"/info >/dev/null &&
-                       go_next && continue
-
-               test -s "$dotest/patch" || {
-                       eval_gettextln "Patch is empty.  Was it split wrong?
-If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
-To restore the original branch and stop patching run \"\$cmdline --abort\"."
-                       stop_here $this
-               }
-               rm -f "$dotest/original-commit" "$dotest/author-script"
-               if test -f "$dotest/rebasing" &&
+               if test -f "$dotest/rebasing"
+               then
                        commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
                                -e q "$dotest/$msgnum") &&
-                       test "$(git cat-file -t "$commit")" = commit
-               then
+                       test "$(git cat-file -t "$commit")" = commit ||
+                               stop_here $this
                        git cat-file commit "$commit" |
                        sed -e '1,/^$/d' >"$dotest/msg-clean"
-                       echo "$commit" > "$dotest/original-commit"
-                       get_author_ident_from_commit "$commit" > "$dotest/author-script"
+                       echo "$commit" >"$dotest/original-commit"
+                       get_author_ident_from_commit "$commit" >"$dotest/author-script"
+                       git diff-tree --root --binary "$commit" >"$dotest/patch"
                else
+                       git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
+                               <"$dotest/$msgnum" >"$dotest/info" ||
+                               stop_here $this
+
+                       # skip pine's internal folder data
+                       sane_grep '^Author: Mail System Internal Data$' \
+                               <"$dotest"/info >/dev/null &&
+                               go_next && continue
+
+                       test -s "$dotest/patch" || {
+                               eval_gettextln "Patch is empty.  Was it split wrong?
+If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
+To restore the original branch and stop patching run \"\$cmdline --abort\"."
+                               stop_here $this
+                       }
+                       rm -f "$dotest/original-commit" "$dotest/author-script"
                        {
                                sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
                                echo
index 04d89415fe8ca1634fa362c66ea9569794dcadd5..392ebc9790c88f9857fc4e943d1fe6351e953c7d 100644 (file)
@@ -3,8 +3,6 @@
 # Copyright (c) 2010 Junio C Hamano.
 #
 
-. git-sh-setup
-
 case "$action" in
 continue)
        git am --resolved --resolvemsg="$resolvemsg" &&
index 5f566726abd51bed534806415207b989d377eeab..3a3c3823571162853e4e88876e7646287c7c1af5 100644 (file)
@@ -9,9 +9,7 @@
 #
 # The original idea comes from Eric W. Biederman, in
 # http://article.gmane.org/gmane.comp.version-control.git/22407
-
-. git-sh-setup
-
+#
 # The file containing rebase commands, comments, and empty lines.
 # This file is created by "git rebase -i" then edited by the user.  As
 # the lines are processed, they are removed from the front of this
index dc599077f0e55472ae814ed4e15f5b3a1b729caf..b10f2cf21b904bbbc3fafc27d183d8ad7917b479 100644 (file)
@@ -3,8 +3,6 @@
 # Copyright (c) 2010 Junio C Hamano.
 #
 
-. git-sh-setup
-
 prec=4
 
 read_state () {
index 6bd8eae6480033b353d1d86403fc9f2067d8e502..5bddfa9690e8dfbedd07e31dc7e768b60f156213 100755 (executable)
@@ -414,6 +414,7 @@ else
        test -z "$onto" && die "You must specify --onto when using --root"
        unset upstream_name
        unset upstream
+       test $# -gt 1 && usage
        upstream_arg=--root
 fi
 
@@ -464,7 +465,7 @@ case "$#" in
                die "fatal: no such branch: $1"
        fi
        ;;
-*)
+0)
        # Do not need to switch branches, we are already on it.
        if branch_name=`git symbolic-ref -q HEAD`
        then
@@ -476,6 +477,9 @@ case "$#" in
        fi
        orig_head=$(git rev-parse --verify "${branch_name}^0") || exit
        ;;
+*)
+       die "BUG: unexpected number of arguments left to parse"
+       ;;
 esac
 
 require_clean_work_tree "rebase" "Please commit or stash them."
index e5ad67c643ffee9b79fce813673732faa950714f..19eddadcf734951b22246c6dd0a16d517f111b5b 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-test_description='rebase should not insist on git message convention'
+test_description='rebase should handle arbitrary git message'
 
 . ./test-lib.sh
 
@@ -12,6 +12,11 @@ It has two paragraphs, but its first paragraph is not friendly
 to oneline summary format.
 EOF
 
+cat >G <<\EOF
+commit log message containing a diff
+EOF
+
+
 test_expect_success setup '
 
        >file1 &&
@@ -19,8 +24,9 @@ test_expect_success setup '
        git add file1 file2 &&
        test_tick &&
        git commit -m "Initial commit" &&
+       git branch diff-in-message
 
-       git checkout -b side &&
+       git checkout -b multi-line-subject &&
        cat F >file2 &&
        git add file2 &&
        test_tick &&
@@ -28,6 +34,17 @@ test_expect_success setup '
 
        git cat-file commit HEAD | sed -e "1,/^\$/d" >F0 &&
 
+       git checkout diff-in-message &&
+       echo "commit log message containing a diff" >G &&
+       echo "" >>G
+       cat G >file2 &&
+       git add file2 &&
+       git diff --cached >>G &&
+       test_tick &&
+       git commit -F G &&
+
+       git cat-file commit HEAD | sed -e "1,/^\$/d" >G0 &&
+
        git checkout master &&
 
        echo One >file1 &&
@@ -36,13 +53,20 @@ test_expect_success setup '
        git commit -m "Second commit"
 '
 
-test_expect_success rebase '
+test_expect_success 'rebase commit with multi-line subject' '
 
-       git rebase master side &&
+       git rebase master multi-line-subject &&
        git cat-file commit HEAD | sed -e "1,/^\$/d" >F1 &&
 
        test_cmp F0 F1 &&
        test_cmp F F0
 '
 
+test_expect_success 'rebase commit with diff in message' '
+       git rebase master diff-in-message &&
+       git cat-file commit HEAD | sed -e "1,/^$/d" >G1 &&
+       test_cmp G0 G1 &&
+       test_cmp G G0
+'
+
 test_done
index 086c91c7b47aa2fa7b593f4f9b2f84f6b7ba3724..1e9d1a737c5369d1b41bfa75f5939ad41004b944 100755 (executable)
@@ -23,9 +23,15 @@ test_expect_success 'prepare repository' '
 '
 
 test_expect_success 'rebase --root expects --onto' '
+       git checkout -B fail other &&
        test_must_fail git rebase --root
 '
 
+test_expect_success 'rebase --root fails with too many args' '
+       git checkout -B fail other &&
+       test_must_fail git rebase --onto master --root fail fail
+'
+
 test_expect_success 'setup pre-rebase hook' '
        mkdir -p .git/hooks &&
        cat >.git/hooks/pre-rebase <<EOF &&
@@ -42,7 +48,7 @@ cat > expect <<EOF
 EOF
 
 test_expect_success 'rebase --root --onto <newbase>' '
-       git checkout -b work &&
+       git checkout -b work other &&
        git rebase --root --onto master &&
        git log --pretty=tformat:"%s" > rebased &&
        test_cmp expect rebased