summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2007-11-07 18:18:56 +0100
committerHans Ulrich Niedermann <hun@n-dimensional.de>2007-11-07 18:18:56 +0100
commit51f6dc28af869d244f534575340788b213e69ecb (patch)
tree01b747e00b92274324bd3a48ea25e1bbbb54886e
parentd0c49a5da9e93c134b5a03349b0b4fe453a26a4b (diff)
downloadndim-git-utils-51f6dc28af869d244f534575340788b213e69ecb.tar.gz
ndim-git-utils-51f6dc28af869d244f534575340788b213e69ecb.tar.xz
ndim-git-utils-51f6dc28af869d244f534575340788b213e69ecb.zip
git-rebase-subtree: Preliminary implementation
-rw-r--r--git-follow/git-follow.in118
1 files changed, 115 insertions, 3 deletions
diff --git a/git-follow/git-follow.in b/git-follow/git-follow.in
index 7d8d4b6..b98aa1d 100644
--- a/git-follow/git-follow.in
+++ b/git-follow/git-follow.in
@@ -1,4 +1,43 @@
#!/bin/sh
+#
+# Note: Letters A-Z are branch names, not revs.
+#
+# Old tree:
+# *--F
+# /
+# origin=master--A--B--G
+# \
+# *--D--H
+# \
+# *--*--K
+#
+# Set "git config follow.tree" to:
+# master A
+# A B
+# B F
+# B G
+# A D
+# D H
+# D K
+#
+# After "git-fetch -v":
+# *--F
+# /
+# master---A--B--G
+# \ \
+# * *--D--H
+# \ \
+# *--origin' *--*--K
+#
+# After "git-rebase-subtree origin master":
+#
+# *'--F'
+# /
+# origin'=master'--A'--B'--G'
+# \
+# *'--D'--H'
+# \
+# *'--*'--K'
unset CDPATH
SED="${SED-sed}"
@@ -21,24 +60,97 @@ require_work_tree
# Abort on error
set -e
+
+cmd() {
+ echo "CMD>" "$@"
+ gitk --all
+ "$@"
+}
+
+
gf_init() {
+ echo "$self: Examining configuration"
git config follow.tree | while read from to restofline; do
if test "x#" = "x$(echo "$from" | sed -n '1s/^\(.\).*/\1/p')"; then continue; fi
- echo "ITEM"
+ echo ""
echo " From: $from"
echo " To: $to"
done
}
+gf_branch() {
+ branch="$1"
+ newbranch="follow-old/$branch"
+ if git-rev-parse --verify "$branch" > /dev/null 2>&1; then
+ # valid branch
+ if git-rev-parse --verify "$newbranch" > /dev/null 2>&1; then
+ : # branch already exists, do nothing
+ else
+ cmd git-branch "${newbranch}" "${branch}"
+ fi
+ else
+ echo "$self: gf_branch called with invalid branch \"$branch\"" >&2
+ exit 1
+ fi
+}
+
+
+gf_rmbranch() {
+ branch="$1"
+ newbranch="follow-old/$branch"
+ if git-rev-parse --verify "$branch" > /dev/null 2>&1; then
+ if git-rev-parse --verify "$newbranch" > /dev/null 2>&1; then
+ cmd git-branch -D "${newbranch}"
+ fi
+ fi
+}
+
+
+gf_rebase_tree() {
+ newroot="$1"
+ test "x$newroot" = "x" && die "Need <newroot> parameter"
+ oldroot="$2"
+ test "x$oldroot" = "x" && die "Need <oldroot> parameter"
+ echo
+ echo "$self: Preparing subtree rebase"
+ git config follow.tree | while read from to restofline; do
+ if test "x#" = "x$(echo "$from" | sed -n '1s/^\(.\).*/\1/p')"; then continue; fi
+ gf_branch "$from"
+ gf_branch "$to"
+ done
+ gitk --all
+ echo
+ echo "$self: Executing subtree rebase"
+ git config follow.tree | while read from to restofline; do
+ if test "x#" = "x$(echo "$from" | sed -n '1s/^\(.\).*/\1/p')"; then continue; fi
+ cmd git-rebase --onto "$from" "follow-old/$from" "$to"
+ done
+ gitk --all
+ echo
+ echo "$self: Cleaning up after subtree rebase"
+ git config follow.tree | while read from to restofline; do
+ if test "x#" = "x$(echo "$from" | sed -n '1s/^\(.\).*/\1/p')"; then continue; fi
+ gf_rmbranch "$from"
+ gf_rmbranch "$to"
+ done
+ gitk --all
+}
+
+
# The great command case
command="$1"
if shift; then
- case "$command" in *)
+ case "$command" in
+ rebase-subtree)
+ gf_init
+ gf_rebase_tree "$@"
+ ;;
+ *)
die "Invalid command line parameter: \"$command\""
;;
esac
else
- die "Command required"
+ gf_init
fi
# End of file.