Skip to contentSkip to conversation

merge: allow merging into a yet-to-be-born branch.

PATCH New Junio C Hamano 1 participant 1 message Aug 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 merge: allow merging into a yet-to-be-born branch.

---

* This is not useful in a freshly initialized repository, since it would not have any commits that you can use with the command. But you can push into the repository and then later use the updated branch to merge into your 'master' branch that still does not exist yet.

 git-merge.sh |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
git-merge.sh +18 -0
index 25deb1e..dd4e83d 100755
@@ -159,6 +159,24 @@ then
 	shift
 	head_arg="$1"
 	shift
+elif ! git-rev-parse --verify HEAD 2>/dev/null
+then
+	# If the merged head is a valid one there is no reason to
+	# forbid "git merge" into a branch yet to be born.  We do
+	# the same for "git pull".
+	if test 1 -ne $#
+	then
+		echo >&2 "Can merge only exactly one commit into empty head"
+		exit 1
+	fi
+
+	rh=$(git rev-parse --verify "$1^0") ||
+		die "$1 - not something we can merge"
+
+	git-update-ref -m "initial pull" HEAD "$rh" "" &&
+	git-read-tree --reset -u HEAD
+	exit
+
 else
 	# We are invoked directly as the first-class UI.
 	head_arg=HEAD
Signature · 1 line
1.4.4.g26805