Skip to content

Commit ed1aadf

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
[PATCH] git fetch --tags
You can do git fetch --tags <linus-kernel-repo> and it should fetch all my tags automatically. [jc: The original by Linus fetched and overwrote branch heads with --all, which felt dangerous and wrong, so I removed it. Also this version does not use any refs that resulted as --tags for later merge. ] Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4fa2197 commit ed1aadf

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

git-fetch.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
66
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
77

8+
tags=
89
append=
910
force=
1011
update_head_ok=
@@ -17,6 +18,9 @@ do
1718
-f|--f|--fo|--for|--forc|--force)
1819
force=t
1920
;;
21+
-t|--t|--ta|--tag|--tags)
22+
tags=t
23+
;;
2024
-u|--u|--up|--upd|--upda|--updat|--update|--update-|--update-h|\
2125
--update-he|--update-hea|--update-head|--update-head-|\
2226
--update-head-o|--update-head-ok)
@@ -158,7 +162,26 @@ case "$update_head_ok" in
158162
;;
159163
esac
160164

161-
for ref in $(get_remote_refs_for_fetch "$@")
165+
# If --tags (and later --heads or --all) is specified, then we are
166+
# not talking about defaults stored in Pull: line of remotes or
167+
# branches file, and just fetch those and refspecs explicitly given.
168+
# Otherwise we do what we always did.
169+
170+
reflist=$(get_remote_refs_for_fetch "$@")
171+
if test "$tags"
172+
then
173+
taglist=$(git-ls-remote --tags "$remote" | awk '{ print "."$2":"$2 }')
174+
if test "$#" -gt 1
175+
then
176+
# remote URL plus explicit refspecs; we need to merge them.
177+
reflist="$reflist $taglist"
178+
else
179+
# No explicit refspecs; fetch tags only.
180+
reflist=$taglist
181+
fi
182+
fi
183+
184+
for ref in $reflist
162185
do
163186
refs="$refs $ref"
164187

0 commit comments

Comments
 (0)