Re: [PATCH v2 02/23] contrib/subtree: Add command from-submodule

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v2 02/23] contrib/subtree: Add command from-submodule

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:56:21

Paul Campbell [off-list ref] writes:
quoted hunk
@@ -721,4 +722,31 @@ cmd_push()
 	fi
 }
 
+cmd_from-submodule()
+{
I know contrib/subtree does not work with anything other than bash,
and bash may accept this as a valid function name, but if you can
avoid it easily I would prefer not to see a non-POSIX construct like
this in my tree, even in contrib/ part:

  http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_230

because people often reference random parts of the tree and mimick
what existing code does.
+	ensure_clean
+
+	local submodule_sha=$(git submodule status $prefix | cut -d ' ' -f 2)
Is $prefix guaranteed not to have any $IFS whitespaces?
+	# Remove references to submodule.
+	git config --remove-section submodule.$prefix
+	git config --file .gitmodules --remove-section submodule.$prefix
+	git add .gitmodules
+
+	# Move submodule aside.
+	local tmp_repo="$(mktemp -d /tmp/git-subtree.XXXXX)"
Doesn't "git subtree" honor TMPDIR?  Not complaining, but being
curious.
+	rm -r $tmp_repo
+	mv $prefix $tmp_repo
+	git rm $prefix
Is $prefix guaranteed not to have any $IFS whitespaces?
+
+	# Commit changes.
+	git commit -m "Remove '$prefix/' submodule"
+
+	# subtree add from submodule repo.
+	cmd_add_repository $tmp_repo HEAD
+
+	# Remove submodule repo.
+	rm -rf $tmp_repo
+}
+
 "cmd_$command" "$@"

[PATCH] contrib/subtree: Add command from-submodule

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:30

Converts a git-submodule into a git-subtree.

Based-on-patch-by: Peter Jaros [off-list ref]
Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.sh | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index a81dfef..5e3c0b8 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -14,6 +14,7 @@ git subtree merge --prefix=<prefix> <commit>
 git subtree pull  --prefix=<prefix> <repository> <refspec...>
 git subtree push  --prefix=<prefix> <repository> <refspec...>
 git subtree split --prefix=<prefix> <commit...>
+git subtree from-submodule --prefix=<prefix>
 --
 h,help        show the help
 q             quiet
@@ -114,7 +115,7 @@ prefix="${prefix%/}";
 command="$1"
 shift
 case "$command" in
-	add|merge|pull) default= ;;
+	add|merge|pull|from-submodule) default= ;;
 	split|push) default="--default HEAD" ;;
 	*) die "Unknown command '$command'" ;;
 esac
@@ -140,7 +141,14 @@ if ( test "$command" != "pull" ) && ( test "$command" != "add" ) && ( test "$com
 	fi
 fi
 
+# map command to a function
+case $command in
+	from-submodule) cmd=cmd_from_submodule;;
+	*) cmd="cmd_$command";;
+esac
+
 debug "command: {$command}"
+debug "function: {$function}"
 debug "quiet: {$quiet}"
 debug "revs: {$revs}"
 debug "dir: {$dir}"
@@ -766,4 +774,29 @@ cmd_push()
 	fi
 }
 
-"cmd_$command" "$@"
+cmd_from_submodule()
+{
+	ensure_clean
+
+	# Remove references to submodule.
+	git config --remove-section "submodule.$prefix"
+	git config --file .gitmodules --remove-section "submodule.$prefix"
+	git add .gitmodules
+
+	# Move submodule aside.
+	tmp_repo="$(mktemp -d git-subtree.XXXXX)"
+	rm -r $tmp_repo
+	mv "$prefix" $tmp_repo
+	git rm "$prefix"
+
+	# Commit changes.
+	git commit -m "Remove '$prefix/' submodule"
+
+	# subtree add from submodule repo.
+	cmd_add_repository $tmp_repo HEAD
+
+	# Remove submodule repo.
+	rm -rf $tmp_repo
+}
+
+"$cmd" "$@"
-- 
1.8.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help