]> git.phdru.name Git - git-scripts.git/commitdiff
Feat: Add `clone` script
authorOleg Broytman <phd@phdru.name>
Wed, 11 Oct 2017 21:56:56 +0000 (00:56 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 11 Oct 2017 21:56:56 +0000 (00:56 +0300)
clone [new file with mode: 0755]

diff --git a/clone b/clone
new file mode 100755 (executable)
index 0000000..94932f2
--- /dev/null
+++ b/clone
@@ -0,0 +1,28 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 origin" >&2
+   exit 1
+fi
+
+origin="$1"
+local_repo="`basename \"$origin\" .git`"
+
+if [ -d "$local_repo"/.git ]; then
+   cd "$local_repo"
+fi &&
+
+if [ -d .git ]; then
+   git remote set-url origin "$origin"
+else
+   git clone -o origin "$origin" "$local_repo" &&
+   cd "$local_repo"
+fi &&
+
+pwd >> "`dirname \"$0\"`"/locate-all.list &&
+
+chmod a-x .git/config &&
+branch="`git rev-parse --abbrev-ref HEAD`"
+
+git config push.default current &&
+exec git gc --aggressive