|
@@ -0,0 +1,74 @@
|
|
1
|
+#!/bin/sh
|
|
2
|
+#
|
|
3
|
+# Take first subdir (or a subdir specified in a file) and consider
|
|
4
|
+# it a git repo dir. Get its origin, exchange the last bit for
|
|
5
|
+# other project name and clone the other repo
|
|
6
|
+#
|
|
7
|
+# This is useful if you have a local dir where you store repos
|
|
8
|
+# for various projects from a common namespace that differ only
|
|
9
|
+# in last part of the remote URI. Now all you need to do to
|
|
10
|
+# clone new one is "git sibling aproject". The script will
|
|
11
|
+# do the rest for you including sniffing the URI.
|
|
12
|
+#
|
|
13
|
+# The script simply takes the first subdir. In case this is not
|
|
14
|
+# OK for you (e.g. the dir id likely to be empty or contain
|
|
15
|
+# come "non-compliant" repos, you can specify path to the
|
|
16
|
+# other "template" repo in .git-universe-sibling file.
|
|
17
|
+#
|
|
18
|
+# Hint: regarding the "template" repo, you can easily create
|
|
19
|
+# a "fake" repo that would sit elsewhere, e.g.:
|
|
20
|
+# $ mkdir .some/hidden/dir
|
|
21
|
+# $ cd .some/hidden/dir
|
|
22
|
+# $ git init
|
|
23
|
+# $ git remote add origin ssh://our_server/projects/FAKE
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+## cfgz
|
|
27
|
+#
|
|
28
|
+
|
|
29
|
+origin_name="origin"
|
|
30
|
+sibling_conf=".git-universe-sibling"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+## funz
|
|
34
|
+#
|
|
35
|
+
|
|
36
|
+rewrite_uri_to () {
|
|
37
|
+ # create a new remote URI based on current one
|
|
38
|
+ git remote -v \
|
|
39
|
+ | grep "^$origin_name" \
|
|
40
|
+ | grep "(fetch)$" \
|
|
41
|
+ | cut -f 2 \
|
|
42
|
+ | cut -d" " -f 1 \
|
|
43
|
+ | perl -pe "s|[^/]+$|$1|;"
|
|
44
|
+}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+## initz
|
|
48
|
+#
|
|
49
|
+
|
|
50
|
+project=$1
|
|
51
|
+
|
|
52
|
+if [ -f $sibling_conf ];
|
|
53
|
+then
|
|
54
|
+ sibling=$(cat $sibling_conf);
|
|
55
|
+else
|
|
56
|
+ sibling=$(find -maxdepth 1 -type d -name "[^.]*" | head -1)
|
|
57
|
+fi
|
|
58
|
+
|
|
59
|
+if [ -z "$sibling" ];
|
|
60
|
+then
|
|
61
|
+ echo "could not find older sibling" 1>&2
|
|
62
|
+ exit 1
|
|
63
|
+fi
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+## body
|
|
67
|
+#
|
|
68
|
+
|
|
69
|
+pushd "$sibling" >/dev/null
|
|
70
|
+new_remote=$(rewrite_uri_to $project)
|
|
71
|
+popd >/dev/null
|
|
72
|
+
|
|
73
|
+echo \'git clone $new_remote\'
|
|
74
|
+git clone $new_remote
|