-
Notifications
You must be signed in to change notification settings - Fork 0
/
git2-clone
executable file
·50 lines (39 loc) · 1.05 KB
/
git2-clone
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
#!/bin/bash
# require library functions
SCRIPTPATH="$(readlink -f 2>/dev/null || perl -MCwd -e 'print Cwd::abs_path shift' $0)"
source "$(dirname "${SCRIPTPATH}")/lib.sh"
git2_search_base_dir
remote_name="origin"
branch_name="master"
# parse git clone arguments:
while test "x$1" != "x--" && test "x${1:0:1}" == "x-"; do
if test "x$1" = "x-o" || test "x$1" = "x--origin"; then
shift
remote_name="$1"
fi
if test "x$1" = "x-b" || test "x$1" = "x--branch"; then
shift
branch_name="$1"
fi
shift
done
test "x$1" = "x--" && shift
REPO="$1"
DIR="$2"
if test "x${REPO}" = "x"
then
echo "No Repository given"
fi
if test "x${DIR}" = "x"
then
DIR="."
fi
git2 init "${DIR}" && \
git2 remote add "${remote_name}" "${REPO}" && \
git2 fetch && \
git2 branch --track "${branch_name}" "${remote_name}/${branch_name}" &&\
git2 reset -q && \
git2 checkout-index -a
# git2 branch ... = checkout without overwriting existing files:
# old: git2 checkout -b "${branch_name}" --track "${remote_name}/${branch_name}"
# git2 checkout-index -a = creates deleted files