Skip to content

Commit 5677882

Browse files
author
Junio C Hamano
committed
git-fetch: allow glob pattern in refspec
This adds Andy's refspec glob. You can have a single line: Pull: refs/heads/*:refs/remotes/origin/* in your ".git/remotes/origin" and say "git fetch" to retrieve all refs under heads/ at the remote side to remotes/origin/ in the local repository. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2986c02 commit 5677882

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

git-parse-remote.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,39 @@ get_remote_default_refs_for_push () {
9090
esac
9191
}
9292

93+
# Called from canon_refs_list_for_fetch -d "$remote", which
94+
# is called from get_remote_default_refs_for_fetch to grok
95+
# refspecs that are retrieved from the configuration, but not
96+
# from get_remote_refs_for_fetch when it deals with refspecs
97+
# supplied on the command line. $ls_remote_result has the list
98+
# of refs available at remote.
99+
expand_refs_wildcard () {
100+
for ref
101+
do
102+
# a non glob pattern is given back as-is.
103+
expr "z$ref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev/null || {
104+
echo "$ref"
105+
continue
106+
}
107+
from=`expr "z$ref" : 'z\(refs/.*/\)\*:refs/.*/\*$'`
108+
to=`expr "z$ref" : 'zrefs/.*/\*:\(refs/.*/\)\*$'`
109+
echo "$ls_remote_result" |
110+
(
111+
IFS=' '
112+
while read sha1 name
113+
do
114+
mapped=${name#"$from"}
115+
if test "z$name" != "z${name#'^{}'}" ||
116+
test "z$name" = "z$mapped"
117+
then
118+
continue
119+
fi
120+
echo "${name}:${to}${mapped}"
121+
done
122+
)
123+
done
124+
}
125+
93126
# Subroutine to canonicalize remote:local notation.
94127
canon_refs_list_for_fetch () {
95128
# If called from get_remote_default_refs_for_fetch
@@ -107,6 +140,8 @@ canon_refs_list_for_fetch () {
107140
merge_branches=$(git-repo-config \
108141
--get-all "branch.${curr_branch}.merge")
109142
fi
143+
set x $(expand_refs_wildcard "$@")
144+
shift
110145
fi
111146
for ref
112147
do

0 commit comments

Comments
 (0)