-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit-remote-push
executable file
·61 lines (48 loc) · 1.25 KB
/
git-remote-push
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
#!/usr/bin/env bash
#
# Before there was `git config receive.denyCurrentBranch updateInstead`, I used this
# to update working trees on a remote server.
#
# DEPENDENCIES: `git-bottle` (see repo).
#
if [ "$#" -eq 0 ] ; then
echo "Expected host:path or remote-name" >&2
exit -1
fi
set -u
set -e
REMOTE_DESC="$1"
shift 1
arr=(`echo $REMOTE_DESC | tr ':' ' '`)
if [[ ${#arr[@]} == 1 ]] ; then
# No ':" in provided name
while read -r line ; do
remote_name=$(echo $line | awk -F" " '{print $1}')
remote_url=$(echo $line | awk -F" " '{print $2}')
if [[ "${remote_name}" == "${REMOTE_DESC}" ]] ; then
REMOTE_DESC=${remote_url}
break
fi
done < <(git remote -v | grep push)
arr=(`echo $REMOTE_DESC | tr ':' ' '`)
if [[ ${#arr[@]} == 1 ]] || [[ ${#arr[@]} == 0 ]]; then
echo "Could not figure out remote path"
exit -1
fi
fi
dest=${arr[0]}
remote_path=${arr[1]}
if [ -z "$dest" ] ; then
echo "Destination not specified" >&2
exit -1
fi
if [ -z "$remote_path" ] ; then
echo "Path on destination not specified" >&2
exit -1
fi
branch=master
git-bottle
version=`git rev-parse HEAD`
git-unbottle
git push "$@" -f ${dest}:${remote_path} ${version}:${branch}
ssh -t ${dest} "cd ${remote_path} && git reset --hard ${branch}"