Skip to contentSkip to conversation

git-submodule: make it easier to use alternate urls

PATCH In review Lars Hjemli 4 participants 11 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

cover git-submodule: make it easier to use alternate urls

This patch-series teaches git-submodule to register submodule urls in .git/config during 'git-submodule init' and to perform the actual cloning during 'git-submodule update', using the url stored in .git/config. So now the downstream users can specify their preferred urls for each interesting submodule by editing their .git/config after running 'git-submodule init'.

 Documentation/git-submodule.txt |   16 ++++----
 git-submodule.sh                |   83 ++++++++++++++++++++------------------
 t/t7400-submodule-basic.sh      |   38 ++++++++++++------
 3 files changed, 78 insertions(+), 59 deletions(-)
#1 lore raw

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

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

---
 git-submodule.sh |   44 ++++++++++++++++++++++++++++----------------
 1 files changed, 28 insertions(+), 16 deletions(-)
git-submodule.sh +28 -16
index 6ed5a6c..a89ea88 100755
@@ -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"
Signature · 1 line
1.5.2.841.gc9eafb
#2 lore raw

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

Quoted 1 line · Lars Hjemli

+ 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.

-- Hannes

#3 lore raw

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

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

---

Quoted 11 lines · Johannes Sixt
Quoted 1 line · Lars Hjemli

+ 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(-)
git-submodule.sh +28 -16
index 6ed5a6c..a89ea88 100755
@@ -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"
Signature · 1 line
1.5.2.841.gc9eafb
#4 lore raw

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

Quoted 14 lines · Lars Hjemli

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

---

Quoted 6 lines · Johannes Sixt
Quoted 1 line · Lars Hjemli

+ module_clone "$path" "$url" || exit $?

Minor nit: The idiom that is commonly used in situations like this (see other git-* shell scripts):

Quoted 8 lines
Quoted 5 lines
		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].

This seems to be WS munged by your mailer.

Quoted 9 lines

...

git-submodule.sh +3 -0
+	die "Clone of submodule '$path' failed"
+}
+
  #
  # Run clone + checkout on missing submodules
  #
@@ -40,20 +67,6 @@ modules_init()
  		# repository
#5 lore raw

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

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

---

Quoted 1 line · Junio C Hamano

This seems to be WS munged by your mailer.

Ouch, I didn't notice...

 git-submodule.sh |   44 ++++++++++++++++++++++++++++----------------
 1 files changed, 28 insertions(+), 16 deletions(-)
git-submodule.sh +28 -16
index 6ed5a6c..a89ea88 100755
@@ -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"
Signature · 1 line
1.5.2.841.gc9eafb
#6 lore raw

PATCH 2/2 git-submodule: clone during update, not during init

This teaches 'git-submodule init' to register submodule paths and urls in .git/config instead of actually cloning them. The cloning is now handled as part of 'git-submodule update'.

With this change it is possible to specify preferred/alternate urls for the submodules in .git/config before the submodules are cloned.

---
 Documentation/git-submodule.txt |   16 +++++++-------
 git-submodule.sh                |   41 ++++++++++++++++----------------------
 t/t7400-submodule-basic.sh      |   38 ++++++++++++++++++++++++-----------
 3 files changed, 51 insertions(+), 44 deletions(-)
Documentation/git-submodule.txt +8 -8
index cb0424f..f8fb80f 100644
@@ -23,15 +23,15 @@ status::
 	repository. This command is the default command for git-submodule.
 
 init::
-	Initialize the submodules, i.e. clone the git repositories specified
-	in the .gitmodules file and checkout the submodule commits specified
-	in the index of the containing repository. This will make the
-	submodules HEAD be detached.
+	Initialize the submodules, i.e. register in .git/config each submodule
+	path and url found in .gitmodules. The key used in git/config is
+	`submodule.$path.url`. This command does not alter existing information
+	in .git/config.
 
 update::
-	Update the initialized submodules, i.e. checkout the submodule commits
-	specified in the index of the containing repository. This will make
-	the submodules HEAD be detached.
+	Update the registered submodules, i.e. clone missing submodules and
+	checkout the commit specified in the index of the containing repository.
+	This will make the submodules HEAD be detached.
 
 
 OPTIONS
@@ -50,7 +50,7 @@ OPTIONS
 
 FILES
 -----
-When cloning submodules, a .gitmodules file in the top-level directory
+When initializing submodules, a .gitmodules file in the top-level directory
 of the containing repository is used to find the url of each submodule.
 This file should be formatted in the same way as $GIR_DIR/config. The key
 to each submodule url is "module.$path.url".
git-submodule.sh +17 -24

75 lines not on this page · raw message

t/t7400-submodule-basic.sh +26 -12
index 6274729..3940433 100755
@@ -40,7 +40,7 @@ test_expect_success 'Prepare submodule testing' '
 	git-add a lib z &&
 	git-commit -m "super commit 1" &&
 	mv lib .subrepo &&
-	GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
+	GIT_CONFIG=.gitmodules git-config module.lib.url git://example.com/lib.git
 '
 
 test_expect_success 'status should only print one line' '
@@ -52,41 +52,55 @@ test_expect_success 'status should initially be "missing"' '
 	git-submodule status | grep "^-$rev1"
 '
 
-test_expect_success 'init should fail when path is used by a file' '
+test_expect_success 'init should register submodule url in .git/config' '
+	git-submodule init &&
+	url=$(git-config submodule.lib.url) &&
+	if test "$url" != "git://example.com/lib.git"
+	then
+		echo "[OOPS] init succeeded but submodule url is wrong"
+		false
+	elif ! git-config submodule.lib.url ./.subrepo
+	then
+		echo "[OOPS] init succeeded but update of url failed"
+		false
+	fi
+'
+
+test_expect_success 'update should fail when path is used by a file' '
 	echo "hello" >lib &&
-	if git-submodule init
+	if git-submodule update
 	then
-		echo "[OOPS] init should have failed"
+		echo "[OOPS] update should have failed"
 		false
 	elif test -f lib && test "$(cat lib)" != "hello"
 	then
-		echo "[OOPS] init failed but lib file was molested"
+		echo "[OOPS] update failed but lib file was molested"
 		false
 	else
 		rm lib
 	fi
 '
 
-test_expect_success 'init should fail when path is used by a nonempty directory' '
+test_expect_success 'update should fail when path is used by a nonempty directory' '
 	mkdir lib &&
 	echo "hello" >lib/a &&
-	if git-submodule init
+	if git-submodule update
 	then
-		echo "[OOPS] init should have failed"
+		echo "[OOPS] update should have failed"
 		false
 	elif test "$(cat lib/a)" != "hello"
 	then
-		echo "[OOPS] init failed but lib/a was molested"
+		echo "[OOPS] update failed but lib/a was molested"
 		false
 	else
 		rm lib/a
 	fi
 '
 
-test_expect_success 'init should work when path is an empty dir' '
+test_expect_success 'update should work when path is an empty dir' '
 	rm -rf lib &&
 	mkdir lib &&
-	git-submodule init &&
+	git-submodule update &&
 	head=$(cd lib && git-rev-parse HEAD) &&
 	if test -z "$head"
 	then
@@ -99,7 +113,7 @@ test_expect_success 'init should work when path is an empty dir' '
 	fi
 '
 
-test_expect_success 'status should be "up-to-date" after init' '
+test_expect_success 'status should be "up-to-date" after update' '
 	git-submodule status | grep "^ $rev1"
 '
 
Signature · 1 line
1.5.2.841.gc9eafb
#9 lore raw

PATCH 2/2 git-submodule: clone during update, not during init

In reply to Lars Hjemli

This teaches 'git-submodule init' to register submodule paths and urls in .git/config instead of actually cloning them. The cloning is now handled as part of 'git-submodule update'.

With this change it is possible to specify preferred/alternate urls for the submodules in .git/config before the submodules are cloned.

---
 Documentation/git-submodule.txt |   16 +++++++-------
 git-submodule.sh                |   41 ++++++++++++++++----------------------
 t/t7400-submodule-basic.sh      |   38 ++++++++++++++++++++++++-----------
 3 files changed, 51 insertions(+), 44 deletions(-)
Documentation/git-submodule.txt +8 -8
index cb0424f..f8fb80f 100644
@@ -23,15 +23,15 @@ status::
 	repository. This command is the default command for git-submodule.
 
 init::
-	Initialize the submodules, i.e. clone the git repositories specified
-	in the .gitmodules file and checkout the submodule commits specified
-	in the index of the containing repository. This will make the
-	submodules HEAD be detached.
+	Initialize the submodules, i.e. register in .git/config each submodule
+	path and url found in .gitmodules. The key used in git/config is
+	`submodule.$path.url`. This command does not alter existing information
+	in .git/config.
 
 update::
-	Update the initialized submodules, i.e. checkout the submodule commits
-	specified in the index of the containing repository. This will make
-	the submodules HEAD be detached.
+	Update the registered submodules, i.e. clone missing submodules and
+	checkout the commit specified in the index of the containing repository.
+	This will make the submodules HEAD be detached.
 
 
 OPTIONS
@@ -50,7 +50,7 @@ OPTIONS
 
 FILES
 -----
-When cloning submodules, a .gitmodules file in the top-level directory
+When initializing submodules, a .gitmodules file in the top-level directory
 of the containing repository is used to find the url of each submodule.
 This file should be formatted in the same way as $GIR_DIR/config. The key
 to each submodule url is "module.$path.url".
git-submodule.sh +17 -24

75 lines not on this page · raw message

t/t7400-submodule-basic.sh +26 -12
index 6274729..3940433 100755
@@ -40,7 +40,7 @@ test_expect_success 'Prepare submodule testing' '
 	git-add a lib z &&
 	git-commit -m "super commit 1" &&
 	mv lib .subrepo &&
-	GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
+	GIT_CONFIG=.gitmodules git-config module.lib.url git://example.com/lib.git
 '
 
 test_expect_success 'status should only print one line' '
@@ -52,41 +52,55 @@ test_expect_success 'status should initially be "missing"' '
 	git-submodule status | grep "^-$rev1"
 '
 
-test_expect_success 'init should fail when path is used by a file' '
+test_expect_success 'init should register submodule url in .git/config' '
+	git-submodule init &&
+	url=$(git-config submodule.lib.url) &&
+	if test "$url" != "git://example.com/lib.git"
+	then
+		echo "[OOPS] init succeeded but submodule url is wrong"
+		false
+	elif ! git-config submodule.lib.url ./.subrepo
+	then
+		echo "[OOPS] init succeeded but update of url failed"
+		false
+	fi
+'
+
+test_expect_success 'update should fail when path is used by a file' '
 	echo "hello" >lib &&
-	if git-submodule init
+	if git-submodule update
 	then
-		echo "[OOPS] init should have failed"
+		echo "[OOPS] update should have failed"
 		false
 	elif test -f lib && test "$(cat lib)" != "hello"
 	then
-		echo "[OOPS] init failed but lib file was molested"
+		echo "[OOPS] update failed but lib file was molested"
 		false
 	else
 		rm lib
 	fi
 '
 
-test_expect_success 'init should fail when path is used by a nonempty directory' '
+test_expect_success 'update should fail when path is used by a nonempty directory' '
 	mkdir lib &&
 	echo "hello" >lib/a &&
-	if git-submodule init
+	if git-submodule update
 	then
-		echo "[OOPS] init should have failed"
+		echo "[OOPS] update should have failed"
 		false
 	elif test "$(cat lib/a)" != "hello"
 	then
-		echo "[OOPS] init failed but lib/a was molested"
+		echo "[OOPS] update failed but lib/a was molested"
 		false
 	else
 		rm lib/a
 	fi
 '
 
-test_expect_success 'init should work when path is an empty dir' '
+test_expect_success 'update should work when path is an empty dir' '
 	rm -rf lib &&
 	mkdir lib &&
-	git-submodule init &&
+	git-submodule update &&
 	head=$(cd lib && git-rev-parse HEAD) &&
 	if test -z "$head"
 	then
@@ -99,7 +113,7 @@ test_expect_success 'init should work when path is an empty dir' '
 	fi
 '
 
-test_expect_success 'status should be "up-to-date" after init' '
+test_expect_success 'status should be "up-to-date" after update' '
 	git-submodule status | grep "^ $rev1"
 '
 
Signature · 1 line
1.5.2.841.gc9eafb
#10 lore raw

PATCH 2/2 git-submodule: clone during update, not during init

This teaches 'git-submodule init' to register submodule paths and urls in .git/config instead of actually cloning them. The cloning is now handled as part of 'git-submodule update'.

With this change it is possible to specify preferred/alternate urls for the submodules in .git/config before the submodules are cloned.

---

Changed from '|| exit @?' to '|| exit'.

  Documentation/git-submodule.txt |   16 +++++++-------
  git-submodule.sh                |   41 ++++++++++++++++----------------------
  t/t7400-submodule-basic.sh      |   38 ++++++++++++++++++++++++-----------
  3 files changed, 51 insertions(+), 44 deletions(-)
Documentation/git-submodule.txt +8 -8
index cb0424f..f8fb80f 100644
@@ -23,15 +23,15 @@ status::
  	repository. This command is the default command for git-submodule.
 
  init::
-	Initialize the submodules, i.e. clone the git repositories specified
-	in the .gitmodules file and checkout the submodule commits specified
-	in the index of the containing repository. This will make the
-	submodules HEAD be detached.
+	Initialize the submodules, i.e. register in .git/config each submodule
+	path and url found in .gitmodules. The key used in git/config is
+	`submodule.$path.url`. This command does not alter existing information
+	in .git/config.
 
  update::
-	Update the initialized submodules, i.e. checkout the submodule commits
-	specified in the index of the containing repository. This will make
-	the submodules HEAD be detached.
+	Update the registered submodules, i.e. clone missing submodules and
+	checkout the commit specified in the index of the containing repository.
+	This will make the submodules HEAD be detached.
 
 
  OPTIONS
@@ -50,7 +50,7 @@ OPTIONS
 
  FILES
  -----
-When cloning submodules, a .gitmodules file in the top-level directory
+When initializing submodules, a .gitmodules file in the top-level directory
  of the containing repository is used to find the url of each submodule.
  This file should be formatted in the same way as $GIR_DIR/config. The key
  to each submodule url is "module.$path.url".
git-submodule.sh +17 -24

75 lines not on this page · raw message

t/t7400-submodule-basic.sh +26 -12
index 6274729..3940433 100755
@@ -40,7 +40,7 @@ test_expect_success 'Prepare submodule testing' '
  	git-add a lib z &&
  	git-commit -m "super commit 1" &&
  	mv lib .subrepo &&
-	GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
+	GIT_CONFIG=.gitmodules git-config module.lib.url git://example.com/lib.git
  '
 
  test_expect_success 'status should only print one line' '
@@ -52,41 +52,55 @@ test_expect_success 'status should initially be "missing"' '
  	git-submodule status | grep "^-$rev1"
  '
 
-test_expect_success 'init should fail when path is used by a file' '
+test_expect_success 'init should register submodule url in .git/config' '
+	git-submodule init &&
+	url=$(git-config submodule.lib.url) &&
+	if test "$url" != "git://example.com/lib.git"
+	then
+		echo "[OOPS] init succeeded but submodule url is wrong"
+		false
+	elif ! git-config submodule.lib.url ./.subrepo
+	then
+		echo "[OOPS] init succeeded but update of url failed"
+		false
+	fi
+'
+
+test_expect_success 'update should fail when path is used by a file' '
  	echo "hello" >lib &&
-	if git-submodule init
+	if git-submodule update
  	then
-		echo "[OOPS] init should have failed"
+		echo "[OOPS] update should have failed"
  		false
  	elif test -f lib && test "$(cat lib)" != "hello"
  	then
-		echo "[OOPS] init failed but lib file was molested"
+		echo "[OOPS] update failed but lib file was molested"
  		false
  	else
  		rm lib
  	fi
  '
 
-test_expect_success 'init should fail when path is used by a nonempty directory' '
+test_expect_success 'update should fail when path is used by a nonempty directory' '
  	mkdir lib &&
  	echo "hello" >lib/a &&
-	if git-submodule init
+	if git-submodule update
  	then
-		echo "[OOPS] init should have failed"
+		echo "[OOPS] update should have failed"
  		false
  	elif test "$(cat lib/a)" != "hello"
  	then
-		echo "[OOPS] init failed but lib/a was molested"
+		echo "[OOPS] update failed but lib/a was molested"
  		false
  	else
  		rm lib/a
  	fi
  '
 
-test_expect_success 'init should work when path is an empty dir' '
+test_expect_success 'update should work when path is an empty dir' '
  	rm -rf lib &&
  	mkdir lib &&
-	git-submodule init &&
+	git-submodule update &&
  	head=$(cd lib && git-rev-parse HEAD) &&
  	if test -z "$head"
  	then
@@ -99,7 +113,7 @@ test_expect_success 'init should work when path is an empty dir' '
  	fi
  '
 
-test_expect_success 'status should be "up-to-date" after init' '
+test_expect_success 'status should be "up-to-date" after update' '
  	git-submodule status | grep "^ $rev1"
  '
 
Signature · 1 line
1.5.2.841.gc9eafb
#7 lore raw

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

In reply to Lars Hjemli
Quoted 4 lines · Lars Hjemli
git-submodule.sh +4 -0
+module_clone()
+{
+	path=$1
+	url=$2

git-submodule.sh say() · line 45

Quoted 10 lines
git-submodule.sh +10 -0
+
+	# 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"

What makes you say that '$path' is not a git repository?

skimo

#8 lore raw

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

Quoted 18 lines · Sven Verdoolaege
Quoted 4 lines · Lars Hjemli
git-submodule.sh +4 -0
+module_clone()
+{
+     path=$1
+     url=$2

git-submodule.sh say() · line 45

Quoted 10 lines
git-submodule.sh +10 -0
+
+     # 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"

What makes you say that '$path' is not a git repository?

The function assumes it's only invoked when no repo is present in $path/.git.

Signature · 1 line
larsh