[PATCH RFC 4/4] rebase -i: add --refs option to rewrite heads within branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The new option --refs causes the TODO file to contain a "ref" command
for each head pointing to a selected commit, other than the one we are
already rebasing.  The effect of this is that when a branch contains
intermediate branches, like so:

      part1 part2 topic
        |     |     |
        v     v     v
  A--*--*--*--*--*--*
   \
    B <--master

a single command like "git rebase -i --refs master topic" suffices to
rewrite all the heads that are part of the topic, like so:

        part1 part2 topic
  A       |     |     |
   \      v     v     v
    B--*--*--*--*--*--*
    ^
    |
    master

Signed-off-by: Greg Price <price@xxxxxxxxxxx>
---
 git-rebase--interactive.sh |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 25ac3e3..cccb031 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -18,6 +18,7 @@ git-rebase [-i] (--continue | --abort | --skip)
  Available options are
 v,verbose          display a diffstat of what changed upstream
 onto=              rebase onto given branch instead of upstream
+refs               rewrite intermediate heads on branch
 p,preserve-merges  try to recreate merges instead of ignoring them
 s,strategy=        use the given merge strategy
 m,merge            always used (no-op)
@@ -42,6 +43,7 @@ REWRITTEN="$DOTEST"/rewritten
 DROPPED="$DOTEST"/dropped
 PRESERVE_MERGES=
 STRATEGY=
+REWRITE_REFS=
 ONTO=
 VERBOSE=
 OK_TO_SKIP_PRE_REBASE=
@@ -578,6 +580,9 @@ first and then run 'git rebase --continue' again."
 
 		output git reset --hard && do_rest
 		;;
+	--refs)
+		REWRITE_REFS=t
+		;;
 	-s)
 		case "$#,$1" in
 		*,*=*)
@@ -705,11 +710,14 @@ first and then run 'git rebase --continue' again."
 			REVISIONS=$ONTO...$HEAD
 			SHORTREVISIONS=$SHORTHEAD
 		fi
-		git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
-			--abbrev=7 --reverse --left-right --topo-order \
+		git rev-list $MERGES_OPTION --abbrev-commit --abbrev=7 \
+			--reverse --left-right --topo-order \
+			--pretty=format:"$(printf '%%m%%h %%s\n%%m%%D')" \
 			$REVISIONS | \
 			sed -n "s/^>//p" | while read shortsha1 rest
 		do
+			read refs
+
 			if test t != "$PRESERVE_MERGES"
 			then
 				echo "pick $shortsha1 $rest" >> "$TODO"
@@ -734,6 +742,16 @@ first and then run 'git rebase --continue' again."
 					echo "pick $shortsha1 $rest" >> "$TODO"
 				fi
 			fi
+
+			if test t = "$REWRITE_REFS"
+			then
+				for ref in $refs
+				do
+					test ${ref#refs/heads/} != $ref &&
+					test $ref != $(cat "$DOTEST"/head-name) &&
+					echo "ref $ref" >> "$TODO"
+				done
+			fi
 		done
 
 		# Watch for commits that been dropped by --cherry-pick
-- 
1.6.6.rc1.9.g2ad41.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]