1#!/bin/sh 2 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. 5GIT_DIR=$(git rev-parse -q --git-dir) || :; 6 7get_default_remote () { 8 curr_branch=$(git symbolic-ref -q HEAD) 9 curr_branch="${curr_branch#refs/heads/}" 10 origin=$(git config --get"branch.$curr_branch.remote") 11echo${origin:-origin} 12} 13 14get_remote_merge_branch () { 15case"$#"in 160|1) 17 origin="$1" 18 default=$(get_default_remote) 19test -z"$origin"&& origin=$default 20 curr_branch=$(git symbolic-ref -q HEAD) && 21["$origin"="$default"] && 22echo $(git for-each-ref --format='%(upstream)'$curr_branch) 23;; 24*) 25 repo=$1 26shift 27 ref=$1 28# FIXME: It should return the tracking branch 29# Currently only works with the default mapping 30case"$ref"in 31+*) 32 ref=$(expr"z$ref":'z+\(.*\)') 33;; 34esac 35expr"z$ref":'z.*:'>/dev/null || ref="${ref}:" 36 remote=$(expr"z$ref":'z\([^:]*\):') 37case"$remote"in 38''| HEAD ) remote=HEAD ;; 39 heads/*) remote=${remote#heads/};; 40 refs/heads/*) remote=${remote#refs/heads/};; 41 refs/* | tags/* | remotes/* ) remote= 42esac 43[-n"$remote"] &&case"$repo"in 44 .) 45echo"refs/heads/$remote" 46;; 47*) 48echo"refs/remotes/$repo/$remote" 49;; 50esac 51esac 52} 53 54error_on_missing_default_upstream () { 55 cmd="$1" 56 op_type="$2" 57 op_prep="$3" 58 example="$4" 59 branch_name=$(git symbolic-ref -q HEAD) 60iftest -z"$branch_name" 61then 62echo"You are not currently on a branch, so I cannot use any 63'branch.<branchname>.merge' in your configuration file. 64Please specify which branch you want to$op_type$op_prepon the command 65line and try again (e.g. '$example'). 66See git-${cmd}(1) for details." 67else 68echo"You asked me to$cmdwithout telling me which branch you 69want to$op_type$op_prep, and 'branch.${branch_name#refs/heads/}.merge' in 70your configuration file does not tell me, either. Please 71specify which branch you want to use on the command line and 72try again (e.g. '$example'). 73See git-${cmd}(1) for details. 74 75If you often$op_type$op_prepthe same branch, you may want to 76use something like the following in your configuration file: 77 [branch\"${branch_name#refs/heads/}\"] 78 remote = <nickname> 79 merge = <remote-ref>" 80test rebase ="$op_type"&& 81echo" rebase = true" 82echo" 83 [remote\"<nickname>\"] 84 url = <url> 85 fetch = <refspec> 86 87See git-config(1) for details." 88fi 89exit1 90}