3 # git-ls-remote could be called from outside a git managed repository;
4 # this would fail in that case and would issue an error message.
5 GIT_DIR=$(git rev-parse -q --git-dir) || :;
16 if test "$(git config --get "remote.$1.url")"
19 elif test -f "$GIT_DIR/remotes/$1"
22 elif test -f "$GIT_DIR/branches/$1"
32 data_source=$(get_data_source "$1")
33 case "$data_source" in
41 git config --get "remote.$1.url"
47 }' "$GIT_DIR/remotes/$1"
50 sed -e 's/#.*//' "$GIT_DIR/branches/$1"
53 die "internal error: get-remote-url $1" ;;
57 get_default_remote () {
58 curr_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
59 origin=$(git config --get "branch.$curr_branch.remote")
60 echo ${origin:-origin}
63 get_remote_merge_branch () {
67 default=$(get_default_remote)
68 test -z "$origin" && origin=$default
69 curr_branch=$(git symbolic-ref -q HEAD) &&
70 [ "$origin" = "$default" ] &&
71 echo $(git for-each-ref --format='%(upstream)' $curr_branch)
77 # FIXME: It should return the tracking branch
78 # Currently only works with the default mapping
81 ref=$(expr "z$ref" : 'z+\(.*\)')
84 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
85 remote=$(expr "z$ref" : 'z\([^:]*\):')
87 '' | HEAD ) remote=HEAD ;;
88 heads/*) remote=${remote#heads/} ;;
89 refs/heads/*) remote=${remote#refs/heads/} ;;
90 refs/* | tags/* | remotes/* ) remote=
92 [ -n "$remote" ] && case "$repo" in
94 echo "refs/heads/$remote"
97 echo "refs/remotes/$repo/$remote"
103 error_on_missing_default_upstream () {
108 branch_name=$(git symbolic-ref -q HEAD)
109 if test -z "$branch_name"
111 echo "You are not currently on a branch, so I cannot use any
112 'branch.<branchname>.merge' in your configuration file.
113 Please specify which branch you want to $op_type $op_prep on the command
114 line and try again (e.g. '$example').
115 See git-${cmd}(1) for details."
117 echo "You asked me to $cmd without telling me which branch you
118 want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in
119 your configuration file does not tell me, either. Please
120 specify which branch you want to use on the command line and
121 try again (e.g. '$example').
122 See git-${cmd}(1) for details.
124 If you often $op_type $op_prep the same branch, you may want to
125 use something like the following in your configuration file:
126 [branch \"${branch_name#refs/heads/}\"]
128 merge = <remote-ref>"
129 test rebase = "$op_type" &&
130 echo " rebase = true"
132 [remote \"<nickname>\"]
136 See git-config(1) for details."