-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-pipe-fetch-pack
executable file
·78 lines (70 loc) · 1.6 KB
/
git-pipe-fetch-pack
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
#!/bin/sh
USAGE='[--write-refs file] [git-fetch-pack options]'
OPTIONS_SPEC=
SUBDIRECTORY_OK=Yes
save () {
what="$1"
shift
for i; do
if test "$what" = opts && printf %s\\n "$i" | grep -q -- "^--"; then
:
elif test "$what" = args && printf %s\\n "$i" | grep -qv -- "^--"; then
:
elif test "$what" = all; then
:
else
continue
fi
# escape : for socat
i=$(printf %s\\n "$i" | sed "s/:/\\\:/g")
printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"
echo " "
done
unset what i
}
. "$(git --exec-path)/git-sh-setup"
write_refs=
i=1
while test ! $i -gt $# ; do
eval "ival=\$$i"
eval "jval=\$$((i+1))"
case "$ival" in
--write-refs=*)
write_refs=$(printf %s\\n "$ival" | sed 's/--write-refs=//')
shift
;;
--write-refs)
if test -n "$jval" && printf %s\\n "$jval" | grep -qv -- "^-"; then
write_refs="$jval"
shift 2
else
usage
fi
;;
esac
i=$((i+1))
done
unset i ival jval
opts=$(save opts "$@")
args=$(save args "$@")
# fetch-pack apparently needs some refs
if test -z "$args" && printf %s\\n "$opts" | grep -qv -- "--all"; then
eval "set -- $opts --all . $args"
else
eval "set -- $opts . $args"
fi
unset opts args
socat=$(which socat)
if test -z "$socat" || test ! -x "$socat"; then
die "This command requires socat(1)"
fi
gfpcmd="git fetch-pack --upload-pack=\\\"$socat - 5 #\\\" $@"
if test -n "$write_refs"; then
if touch "$write_refs" && test -w "$write_refs"; then
:
else
die "$write_refs not writeable"
fi
gfpcmd="$gfpcmd \>$write_refs"
fi
$socat STDIO SYSTEM:"$gfpcmd",fdin=5