Skip to content

Commit 46b1c7c

Browse files
author
Junio C Hamano
committed
Teach git push .git/branches shorthand
Although it is uncertain if we would keep .git/branches for long, the shorthand stored there can be used for pushing if it is host:path/to/git format, so let's make use of it. This does not use git-parse-remote because that script will be rewritten quite a bit for updated pulling. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 972b6fe commit 46b1c7c

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

git-push-script

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,64 @@
11
#!/bin/sh
22
. git-sh-setup-script || die "Not a git archive"
3-
git-send-pack "$@"
3+
4+
# Parse out parameters and then stop at remote, so that we can
5+
# translate it using .git/branches information
6+
has_all=
7+
has_force=
8+
has_exec=
9+
remote=
10+
11+
while case "$#" in 0) break ;; esac
12+
do
13+
case "$1" in
14+
--all)
15+
has_all=--all ;;
16+
--force)
17+
has_force=--force ;;
18+
--exec=*)
19+
has_exec="$1" ;;
20+
-*)
21+
die "Unknown parameter $1" ;;
22+
*)
23+
remote="$1"
24+
shift
25+
set x "$@"
26+
shift
27+
break ;;
28+
esac
29+
shift
30+
done
31+
32+
case "$remote" in
33+
*:* | /* | ../* | ./* )
34+
# An URL, host:/path/to/git, absolute and relative paths.
35+
;;
36+
* )
37+
# Shorthand
38+
if expr "$remote" : '..*/..*' >/dev/null
39+
then
40+
# a short-hand followed by a trailing path
41+
shorthand=$(expr "$remote" : '\([^/]*\)')
42+
remainder=$(expr "$remote" : '[^/]*\(/.*\)$')
43+
else
44+
shorthand="$remote"
45+
remainder=
46+
fi
47+
remote=$(sed -e 's/#.*//' "$GIT_DIR/branches/$remote") &&
48+
expr "$remote" : '..*:' >/dev/null &&
49+
remote="$remote$remainder" ||
50+
die "Cannot parse remote $remote"
51+
;;
52+
esac
53+
54+
case "$remote" in
55+
http://* | https://* | git://* | rsync://* )
56+
die "Cannot push to $remote" ;;
57+
esac
58+
59+
set x "$remote" "$@"; shift
60+
test "$has_all" && set x "$has_all" "$@" && shift
61+
test "$has_force" && set x "$has_force" "$@" && shift
62+
test "$has_exec" && set x "$has_exec" "$@" && shift
63+
64+
exec git-send-pack "$@"

0 commit comments

Comments
 (0)