Make "git fetch" able to fetch a named tag
[git] / git-fetch-script
1 #!/bin/sh
2 #
3 destination=FETCH_HEAD
4
5 merge_repo=$1
6 merge_name=${2:-HEAD}
7 if [ "$2" = "tag" ]; then
8         merge_name="refs/tags/$3"
9         destination="$merge_name"
10 fi
11
12 : ${GIT_DIR=.git}
13 : ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
14
15 download_one () {
16         # remote_path="$1" local_file="$2"
17         case "$1" in
18         http://*)
19                 wget -q -O "$2" "$1" ;;
20         /*)
21                 test -f "$1" && cat >"$2" "$1" ;;
22         *)
23                 rsync -L "$1" "$2" ;;
24         esac
25 }
26
27 download_objects () {
28         # remote_repo="$1" head_sha1="$2"
29         case "$1" in
30         http://*)
31                 git-http-pull -a "$2" "$1/"
32                 ;;
33         /*)
34                 git-local-pull -l -a "$2" "$1/"
35                 ;;
36         *)
37                 rsync -avz --ignore-existing \
38                         "$1/objects/." "$GIT_OBJECT_DIRECTORY"/.
39                 ;;
40         esac
41 }
42
43 echo "Getting remote $merge_name"
44 download_one "$merge_repo/$merge_name" "$GIT_DIR/$destination" || exit 1
45
46 echo "Getting object database"
47 download_objects "$merge_repo" "$(cat "$GIT_DIR/$destination")" || exit 1