Skip to content

Commit efe9bf0

Browse files
author
Junio C Hamano
committed
[PATCH] Allow "+remote:local" refspec to cause --force when fetching.
With this we could say: Pull: master:ko-master +pu:ko-pu to mean "fast forward ko-master with master, overwrite ko-pu with pu", and the latter one does not require the remote "pu" to be descendant of local "ko-pu". Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 521003f commit efe9bf0

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

git-fetch-script

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ fast_forward_local () {
104104
;;
105105
esac || {
106106
echo >&2 "* $1: does not fast forward to $4"
107-
case "$force" in
108-
t)
107+
case "$force,$single_force" in
108+
t,* | *,t)
109109
echo >&2 " from $3; forcing update."
110110
;;
111111
*)
@@ -130,6 +130,13 @@ do
130130

131131
# These are relative path from $GIT_DIR, typically starting at refs/
132132
# but may be HEAD
133+
if expr "$ref" : '\+' >/dev/null
134+
then
135+
single_force=t
136+
ref=$(expr "$ref" : '\+\(.*\)')
137+
else
138+
single_force=
139+
fi
133140
remote_name=$(expr "$ref" : '\([^:]*\):')
134141
local_name=$(expr "$ref" : '[^:]*:\(.*\)')
135142

@@ -175,17 +182,22 @@ http://* | https://* | rsync://* )
175182
while read sha1 remote_name
176183
do
177184
found=
185+
single_force=
178186
for ref in $refs
179187
do
180188
case "$ref" in
189+
+$remote_name:*)
190+
single_force=t
191+
found="$ref"
192+
break ;;
181193
$remote_name:*)
182194
found="$ref"
183195
break ;;
184196
esac
185197
done
186198

187199
local_name=$(expr "$found" : '[^:]*:\(.*\)')
188-
append_fetch_head "$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"
200+
append_fetch_head "$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"
189201
done
190202
;;
191203
esac

git-parse-remote-script

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
get_data_source () {
66
case "$1" in
77
*/*)
8-
# Not so fast. This could be the partial URL shorthand...
8+
# Not so fast. This could be the partial URL shorthand...
99
token=$(expr "$1" : '\([^/]*\)/')
1010
remainder=$(expr "$1" : '[^/]*/\(.*\)')
1111
if test -f "$GIT_DIR/branches/$token"
@@ -69,6 +69,13 @@ get_remote_default_refs_for_push () {
6969
canon_refs_list_for_fetch () {
7070
for ref
7171
do
72+
force=
73+
case "$ref" in
74+
+*)
75+
ref=$(expr "$ref" : '\+\(.*\)')
76+
force=+
77+
;;
78+
esac
7279
expr "$ref" : '.*:' >/dev/null || ref="${ref}:"
7380
remote=$(expr "$ref" : '\([^:]*\):')
7481
local=$(expr "$ref" : '[^:]*:\(.*\)')
@@ -80,7 +87,7 @@ canon_refs_list_for_fetch () {
8087
'') local= ;;
8188
*) local="refs/heads/$local" ;;
8289
esac
83-
echo "${remote}:${local}"
90+
echo "${force}${remote}:${local}"
8491
done
8592
}
8693

@@ -132,12 +139,12 @@ get_remote_refs_for_fetch () {
132139
else
133140
case "$ref" in
134141
tag)
135-
tag_just_seen=yes
142+
tag_just_seen=yes
136143
continue
137144
;;
138145
esac
139146
fi
140-
canon_refs_list_for_fetch "$ref"
147+
canon_refs_list_for_fetch "$ref"
141148
done
142149
;;
143150
esac

0 commit comments

Comments
 (0)