|
| 1 | +: To be included in git-pull and git-fetch scripts. |
| 2 | + |
| 3 | +# A remote repository can be specified on the command line |
| 4 | +# in one of the following formats: |
| 5 | +# |
| 6 | +# <repo> |
| 7 | +# <repo> <head> |
| 8 | +# <repo> tag <tag> |
| 9 | +# |
| 10 | +# where <repo> could be one of: |
| 11 | +# |
| 12 | +# a URL (including absolute or local pathname) |
| 13 | +# a short-hand |
| 14 | +# a short-hand followed by a trailing path |
| 15 | +# |
| 16 | +# A short-hand <name> has a corresponding file $GIT_DIR/branches/<name>, |
| 17 | +# whose contents is a URL, possibly followed by a URL fragment #<head> |
| 18 | +# to name the default branch on the remote side to fetch from. |
| 19 | + |
| 20 | +_remote_repo= _remote_store= _remote_head= _remote_name= |
| 21 | + |
| 22 | +case "$1" in |
| 23 | +*:* | /* | ../* | ./* ) |
| 24 | + _remote_repo="$1" |
| 25 | + ;; |
| 26 | +* ) |
| 27 | + # otherwise, it is a short hand. |
| 28 | + case "$1" in |
| 29 | + */*) |
| 30 | + # a short-hand followed by a trailing path |
| 31 | + _token=$(expr "$1" : '\([^/]*\)/') |
| 32 | + _rest=$(expr "$1" : '[^/]*\(/.*\)$') |
| 33 | + ;; |
| 34 | + *) |
| 35 | + _token="$1" |
| 36 | + _rest= |
| 37 | + _remote_store="refs/heads/$_token" |
| 38 | + ;; |
| 39 | + esac |
| 40 | + test -f "$GIT_DIR/branches/$_token" || |
| 41 | + die "No such remote branch: $_token" |
| 42 | + |
| 43 | + _remote_repo=$(cat "$GIT_DIR/branches/$_token")"$_rest" |
| 44 | + ;; |
| 45 | +esac |
| 46 | + |
| 47 | +case "$_remote_repo" in |
| 48 | +*"#"*) |
| 49 | + _remote_head=`expr "$_remote_repo" : '.*#\(.*\)$'` |
| 50 | + _remote_repo=`expr "$_remote_repo" : '\(.*\)#'` |
| 51 | + ;; |
| 52 | +esac |
| 53 | + |
| 54 | +_remote_name=$(echo "$_remote_repo" | sed 's|\.git/*$||') |
| 55 | + |
| 56 | +case "$2" in |
| 57 | +tag) |
| 58 | + _remote_name="tag '$3' of $_remote_name" |
| 59 | + _remote_head="refs/tags/$3" |
| 60 | + _remote_store="$_remote_head" |
| 61 | + ;; |
| 62 | +?*) |
| 63 | + # command line specified a head explicitly; do not |
| 64 | + # store the fetched head as a branch head. |
| 65 | + _remote_name="head '$2' of $_remote_name" |
| 66 | + _remote_head="refs/heads/$2" |
| 67 | + _remote_store='' |
| 68 | + ;; |
| 69 | +'') |
| 70 | + case "$_remote_head" in |
| 71 | + '') |
| 72 | + _remote_head=HEAD ;; |
| 73 | + *) |
| 74 | + _remote_head="refs/heads/$_remote_head" |
| 75 | + _remote_name="head '$_remote_head' of $_remote_name" |
| 76 | + ;; |
| 77 | + esac |
| 78 | + ;; |
| 79 | +esac |
0 commit comments