-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-clone-bare.sh
More file actions
executable file
·65 lines (52 loc) · 1.18 KB
/
git-clone-bare.sh
File metadata and controls
executable file
·65 lines (52 loc) · 1.18 KB
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
#!/usr/bin/env bash
# -*- coding: UTF-8 -*-
url=""
dir=""
fork=""
while [[ $# -gt 0 ]]; do
case $1 in
--fork)
fork="$2"
shift 2
;;
*)
if [ -z "$url" ]; then
url="$1"
elif [ -z "$dir" ]; then
dir="$1"
fi
shift
;;
esac
done
dir="${dir:-$(basename "$url" .git)}"
if [ -z "$url" ]; then
echo "Usage: git-clone-bare <url> [directory] [--fork <reference>]"
exit 1
fi
if [ -e "$dir" ]; then
echo "Error: $dir already exists"
exit 1
fi
set -eu -o pipefail
git clone --bare "$url" "$dir/.bare"
echo "gitdir: .bare" > "$dir/.git"
git -C "$dir" config core.bare false
git -C "$dir" config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git -C "$dir" fetch origin
if [ -n "$fork" ]; then
git -C "$dir" remote rename origin upstream
git -C "$dir" remote add origin "$fork"
git -C "$dir" fetch origin
fi
cat >> "$dir/.bare/info/exclude" <<'EOF'
/main/
/fix/
/enhancement/
/feature/
EOF
# Detach HEAD so the 'main' branch isn't claimed by .bare
head_sha=$(git -C "$dir" rev-parse HEAD)
echo "$head_sha" > "$dir/.bare/HEAD"
git -C "$dir" worktree add main main
echo "Ready. cd $dir/main to start working."