blob: 9b88d2cee4b0d8dab2a67265764fa002d7d47ff8 (
plain)
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
|
#!/bin/sh
GIT_SERVER=${GIT_SERVER:-"git.tobyvin.dev"}
SCRIPT="$(basename "$0")"
long='help,delete,init,upstream,name:,section:,desc:'
short='hdiu'
if ! opts="$(getopt -o $short -l $long -n "$SCRIPT" -- "$@")"; then
exit 1
fi
eval set -- "$opts"
help() {
cat <<-EOF
$(ssh "git@$GIT_SERVER" -- export --help)
OPTIONS ($SCRIPT)
-i, --init Initialize the bare repository on the remote.
-u, --upstream Set $GIT_SERVER as the remote for the local repo.
--name <NAME> Name of the repository on the remote. By default it
will use the basename of the local repository. This
is also used as the value for cgitrc's repo.name option
--section <SEC> Section name for the section for the repository on cgit.
By default, it will be in root section.
--desc <DESC> Description of the repository. If it is set to '-', the
description will be read from stdin. By default, it will
be blank.
NOTE
This was run via the local git-export helper script. The current
<GIT_DIR> is used in place of <REPO> argument.
EOF
}
if ! local_name=$(git rev-parse --show-toplevel | xargs basename); then
exit 1
fi
upstream_name=$(git remote get-url origin 2>/dev/null | grep -Po "$GIT_SERVER:\K.*")
name=${upstream_name:-$local_name}
init=false
upstream=false
while true; do
case "$1" in
-h | --help)
help
exit 0
;;
-d | --delete) set -- "$@" "$1" ;;
-i | --init) init=true ;;
-u | --upstream) upstream=true ;;
--name)
shift
name="$1"
;;
--section)
shift
set -- "$@" "section='$1'"
;;
--desc)
shift
set -- "$@" "desc='$1'"
;;
--)
shift
break
;;
*)
help
printf "Invalid argument: %s" "$1" 1>&2
exit 1
;;
esac
shift
done
if [ -z "$name" ]; then
printf 'Failed to determine repo name\n' 1>&2
exit 1
fi
if $upstream; then
git remote rm origin 2>/dev/null
git remote add origin git@"$GIT_SERVER":"$name"
fi
if $init; then
ssh "git@$GIT_SERVER" -- init "$name" 2>/dev/null
fi
ssh "git@$GIT_SERVER" -- export "$name" "$@"
|