-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-xclone
executable file
·98 lines (96 loc) · 3.06 KB
/
git-xclone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
# Clone git repository with xtra directory
# vim:se ai si sts=2 sw=2 et:
#############################################################################
# Copyright (c) 2020 Osamu Aoki
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#############################################################################
__help() {
echo "NAME"
echo " git-xclone - Clone a repository to the project name organized directory"
echo "SYNOPSIS"
echo " git xclone URL"
echo "DESCRIPTION"
echo " Clones a repository to the project name organized directory to work with"
echo " multiple projects smoothly. Here, URL is like:"
echo " * https://<repository>/<owner>/<project>.git"
echo " * git@<repository>:<owner>/<project>.git"
echo " The first invocation clones a repository into:"
echo " <project>/<project>"
echo " The following invocations clone repositories into:"
echo " <project>/<repository>/<owner>/<project>"
echo " This should help us organize build results cleanly."
}
# Typical repos
#
# git@salsa.debian.org:debian/ibus.git
# https://salsa.debian.org/debian/ibus.git
#
# git xclone URL
# New: PROJ/PROJ
# Sub: PROJ/REPO/OWNR/PROJ
if [ -n "$1" ]; then
URL="$1"
else
URL="-h"
fi
case "$URL" in
-h | --help) # need help
__help
exit 0
;;
git@*) # git@salsa.debian.org:debian/ibus.git
U="${URL#git@}"
U="${U%.git}"
PROJ="${U#*/}"
U="${U%%/*}"
SITE="${U%%:*}"
OWNR="${U#*:}"
;;
https://*) # https://salsa.debian.org/debian/ibus.git
U="${URL#https://}"
U="${URL%.git}"
PROJ="${U##*/}"
U="${U%/*}"
SITE="${U%%/*}"
OWNR="${U#*/}" # may contain "/"
;;
http://*) # http://foo.bar.org/baz/zzzz.git
U="${URL#http://}"
U="${URL%.git}"
PROJ="${U##*/}"
U="${U%/*}"
SITE="${U%%/*}"
OWNR="${U#*/}" # may contain "/"
;;
*) # others
exit 1
;;
esac
if [ -e "$PROJ" ]; then
mkdir -p "$SITE/$OWNR"
cd "$SITE/$OWNR" || return > /dev/null
git clone "$URL"
else
mkdir -p "$PROJ"
cd "$PROJ" || return > /dev/null
git clone "$URL"
fi
exec