-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffremote
executable file
·56 lines (45 loc) · 1.2 KB
/
offremote
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
#!/bin/bash
# Parse arguments.
while getopts 'hn:f' argument
do
case $argument in
h)
echo "usage: $0 [options] <url>"
echo 'Set up git remote and branch pointing to AUR package repository.'
echo ' -h show this help text'
echo ' -n <name> branch and remote name instead of the repository name'
echo ' -f reconfigure an existing branch'
exit ;;
n) name="$OPTARG" ;;
f) check=false ;;
\?) exit 1 ;;
esac
done
readonly url="${!OPTIND}"
if [ -z "$url" ]
then
gettext -sd bash 'argument expected'
exit 1
fi
# Prepare values.
readonly master="refs/heads/master"
if [ -z "$name" ]
then
name=${url%/}
name=${name##*/}
name=${name%.git}
fi
# Reject reconfiguring an existing branch.
if $check && git rev-parse --verify --quiet "$name" > /dev/null
then
printf "$(gettext -d git "A branch named '%s' already exists.")\n" \
"$name" >&2
exit 1
fi
# Set up remote.
git remote add -t master "$name" "$url" || exit $?
# Restrict parameterless pushes to the branch.
git config "remote.${name}.push" "refs/heads/$name:$master"
# Make branch track remote master.
git config "branch.${name}.remote" "$name"
git config "branch.${name}.merge" "$master"