Skip to content

Instantly share code, notes, and snippets.

@suzak
Created August 17, 2011 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzak/1152012 to your computer and use it in GitHub Desktop.
Save suzak/1152012 to your computer and use it in GitHub Desktop.
diff --git a/git-submodule.sh b/git-submodule.sh
index d189a24..1ab1f70 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -121,12 +121,29 @@ module_clone()
path=$1
url=$2
reference="$3"
+ submodulecachedir=$(git config --path submodule.cachedir)
if test -n "$reference"
then
git-clone "$reference" -n "$url" "$path"
else
- git-clone -n "$url" "$path"
+ if test -n "$submodulecachedir" -a x$(which git-new-workdir) != x
+ then
+ cachedir="$submodulecachedir/$(echo $url | sed -e 's/:/\//g')"
+ if test ! -e "$cachedir"
+ then
+ git-clone -n "$url" "$cachedir"
+ fi
+ if test -e "$path"
+ then
+ # When git-clone parent repository,
+ # git-1.7.4+ makes submodule directory.
+ rmdir "$path"
+ fi
+ git-new-workdir "$cachedir" "$path"
+ else
+ git-clone -n "$url" "$path"
+ fi
fi ||
die "Clone of '$url' into submodule path '$path' failed"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment