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 <junkio@cox.net>
Junio C Hamano committed
Nov 22, 2006 at 23:15 UTC
5677882be721be5e2706a546d90804da8d8d0bd5
1 file changed
+35
git-parse-remote.sh
+35
@@ -90,6 +90,39 @@ get_remote_default_refs_for_push () {
90
esac
91
}
92
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
+
126
# Subroutine to canonicalize remote:local notation.
127
canon_refs_list_for_fetch () {
128
# If called from get_remote_default_refs_for_fetch
@@ -107,6 +140,8 @@ canon_refs_list_for_fetch () {
140
merge_branches=$(git-repo-config \
141
--get-all "branch.${curr_branch}.merge")
142
fi
143
+ set x $(expand_refs_wildcard "$@")
144
+ shift
145
fi
146
for ref
147
do