[PATCH] Add git-unbundle - unpack objects and references for disconnected transfer

From: Mark Levedahl <mdl123@verizon.net>
Date: 2007-02-16 11:19:53
Some workflows require coordinated development between repositories on
machines that can never be connected. This utility unpacks a bundle
containing objects and associated references (heads or tags) into the
current repository, effectively supporting git-push like operations
between disconnected systems.

Signed-off-by: Mark Levedahl <mdl123@verizon.net>
---
 git-unbundle.sh |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 67 insertions(+), 0 deletions(-)
 create mode 100755 git-unbundle.sh

diff --git a/git-unbundle.sh b/git-unbundle.sh
new file mode 100755
index 0000000..ca13305
--- /dev/null
+++ b/git-unbundle.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+# unpack a git-bundle file into current repository
+#
+# See git-bundle.
+
+USAGE="usage: git-unbundle [-f|--force] [file]"
+SUBDIRECTORY_OK=1
+. git-sh-setup
+
+bfile=bundle.tar
+force=
+while case "$#" in 0) break ;; esac
+do
+	case "$1" in
+	-f|--f|--fo|--for|--forc|--force)
+		force=1;;
+	-h|--h|--he|--hel|--help)
+		usage;;
+	-*)
+		die "unknown option: $1";;
+	*)
+		bfile="$1";;
+	esac
+	shift
+done
+
+[ -e "$bfile" ] || die "cannot find $bfile"
+
+# Get prereqs and refs in one go to avoid a third tar invocation.
+# Prereqs come first, are separated by a single - from the actual refs.
+refdata=$(tar -f "$bfile" -x --to-stdout  .gitBundleReferences)
+prereqs="${refdata%%-*}"
+refs="${refdata#*-}"
+
+# check that the prerequisites exist before unbundling.
+for sha1 in $prereqs ; do
+	git-rev-parse --verify $sha1 >& /dev/null || die "Prerequisite commit $sha1 not found."
+done
+
+# get the objects, maybe repack
+tar -f "$bfile" -x --to-stdout .gitBundlePack | git-index-pack --stdin
+
+# check each reference, assure that the result would be valid before updating local ref
+printf "%s %s\n" $refs | while read sha1 ref ; do
+	ok=
+	if [ -z "$force" ] ; then
+		# update only if non-fastforward
+		local=$(git-rev-parse --verify "$ref^0" 2>/dev/null)
+		if [ ! -z "$local" ] ; then
+			mb=$(git-merge-base $local $sha1)
+			if [ "$mb" != "$local" ] ; then
+				echo "Not applying non-fast forward update: $ref"
+			else
+				ok=1
+			fi
+		else
+			ok=1
+		fi
+	else
+		#forced, accept non-fast forward update
+		ok=1
+	fi
+	if [ ! -z "$ok" ] ; then
+		echo "updating: $ref to $sha1"
+		git-update-ref -m "git-unbundle update" $ref $sha1
+	fi
+done
-- 
1.5.0.34.g6afaa


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Fri Feb 16 11:20:22 2007

This archive was generated by hypermail 2.1.8 : 2007-02-16 11:22:46 EST