git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] git-submodule: move cloning into a separate function

From
LHLars Hjemli <hjemli@gmail.com>
Date
Jun 5, 2007, 11:13 UTC
Message-ID
<op.ttf34qd99pspc6@localhost>
In-Reply-To
<46653DB2.997A3ABD@eudaptics.com>

This is just a simple refactoring of modules_init() with no change in functionality.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
On Tue, 05 Jun 2007 12:40:50 +0200, Johannes Sixt <J.Sixt@eudaptics.com> wrote:
Show 11 quoted lines
> Lars Hjemli wrote:
>> +               module_clone "$path" "$url" || exit $?
>
> Minor nit: The idiom that is commonly used in situations like this (see
> other git-* shell scripts):
>
> 		module_clone "$path" "$url" || exit
>
> because exit without argument uses the code of the last command
> executed.
>
Thanks, I'll follow up with matching changes to [patch 2/2].
  git-submodule.sh |   44 ++++++++++++++++++++++++++++----------------
  1 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 6ed5a6c..a89ea88 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -25,6 +25,33 @@ say()
  	fi
  }

+
+#
+# Clone a submodule
+#
+module_clone()
+{
+	path=$1
+	url=$2
+
+	# If there already is a directory at the submodule path,
+	# expect it to be empty (since that is the default checkout
+	# action) and try to remove it.
+	# Note: if $path is a symlink to a directory the test will
+	# succeed but the rmdir will fail. We might want to fix this.
+	if test -d "$path"
+	then
+		rmdir "$path" 2>/dev/null ||
+		die "Directory '$path' exist, but is neither empty nor a git repository"
+	fi
+
+	test -e "$path" &&
+	die "A file already exist at path '$path'"
+
+	git-clone -n "$url" "$path" ||
+	die "Clone of submodule '$path' failed"
+}
+
  #
  # Run clone + checkout on missing submodules
  #
@@ -40,20 +67,6 @@ modules_init()
  		# repository
  		test -d "$path"/.git && continue

-		# If there already is a directory at the submodule path,
-		# expect it to be empty (since that is the default checkout
-		# action) and try to remove it.
-		# Note: if $path is a symlink to a directory the test will
-		# succeed but the rmdir will fail. We might want to fix this.
-		if test -d "$path"
-		then
-			rmdir "$path" 2>/dev/null ||
-			die "Directory '$path' exist, but is neither empty nor a git repository"
-		fi
-
-		test -e "$path" &&
-		die "A file already exist at path '$path'"
-
  		url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
  		test -z "$url" &&
  		die "No url found for submodule '$path' in .gitmodules"
@@ -69,8 +82,7 @@ modules_init()
  		# logical modulename (if present) as key. But this would need
  		# another fallback mechanism if the module wasn't named.

-		git-clone -n "$url" "$path" ||
-		die "Clone of submodule '$path' failed"
+		module_clone "$path" "$url" || exit

  		(unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
  		die "Checkout of submodule '$path' failed"
-- 
1.5.2.841.gc9eafb
Previous: Johannes SixtNext: Junio C Hamano
Message 4 of 11 in “git-submodule: make it easier to use alternate urls”
  1. 0/2 git-submodule: make it easier to use alternate urlsLars Hjemli, Jun 5, 2007
  2. 1/2 git-submodule: move cloning into a separate functionLars Hjemli, Jun 5, 2007
  3. Johannes SixtJun 5, 2007
  4. 1/2 git-submodule: move cloning into a separate functionLars Hjemli, Jun 5, 2007
  5. Junio C HamanoJun 6, 2007
  6. 1/2 git-submodule: move cloning into a separate functionLars Hjemli, Jun 6, 2007
  7. 2/2 git-submodule: clone during update, not during initLars Hjemli, Jun 6, 2007
  8. Sven VerdoolaegeJun 17, 2007
  9. Lars HjemliJun 17, 2007
  10. 2/2 git-submodule: clone during update, not during initLars Hjemli, Jun 5, 2007
  11. 2/2 git-submodule: clone during update, not during initLars Hjemli, Jun 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.