# This is a shell library to calculate the remote repository and # upstream branch that should be pulled by "git pull" from the current # branch. # git-ls-remote could be called from outside a git managed repository; # this would fail in that case and would issue an error message. setglobal GIT_DIR = $[git rev-parse -q --git-dir] || :; proc get_default_remote { setglobal curr_branch = $[git symbolic-ref -q HEAD] setglobal curr_branch = $(curr_branch#refs/heads/) setglobal origin = $[git config --get "branch.$curr_branch.remote] echo $(origin:-origin) } proc get_remote_merge_branch { match "$Argc" { with 0|1 setglobal origin = $1 setglobal default = $[get_default_remote] test -z $origin && setglobal origin = $default setglobal curr_branch = $[git symbolic-ref -q HEAD] && test $origin = $default && echo $[git for-each-ref --format='%(upstream)' $curr_branch] with * setglobal repo = $1 shift setglobal ref = $1 # FIXME: It should return the tracking branch # Currently only works with the default mapping match $ref { with +* setglobal ref = $[expr "z$ref" : 'z+\(.*\)] } expr "z$ref" : 'z.*:' >/dev/null || setglobal ref = ""$(ref):"" setglobal remote = $[expr "z$ref" : 'z\([^:]*\):] match $remote { with '' | HEAD setglobal remote = 'HEAD' with heads/* setglobal remote = $(remote#heads/) with refs/heads/* setglobal remote = $(remote#refs/heads/) with refs/* | tags/* | remotes/* setglobal remote = '' } test -n $remote && match $repo { with . echo "refs/heads/$remote" with * echo "refs/remotes/$repo/$remote" } } } proc error_on_missing_default_upstream { setglobal cmd = $1 setglobal op_type = $2 setglobal op_prep = $3 # FIXME: op_prep is no longer used setglobal example = $4 setglobal branch_name = $[git symbolic-ref -q HEAD] setglobal display_branch_name = $(branch_name#refs/heads/) # If there's only one remote, use that in the suggestion setglobal remote = $[gettext "] setglobal branch = $[gettext "] if test $[git remote | wc -l] = 1 { setglobal remote = $[git remote] } if test -z $branch_name { gettextln "You are not currently on a branch." } else { gettextln "There is no tracking information for the current branch." } match $op_type { with rebase gettextln "Please specify which branch you want to rebase against." with merge gettextln "Please specify which branch you want to merge with." with * echo >&2 "BUG: unknown operation type: $op_type> !2 "BUG: unknown operation type: $op_type" exit 1 } eval_gettextln "See git-\${cmd}(1) for details." echo echo " $example" echo if test -n $branch_name { gettextln "If you wish to set tracking information for this branch you can do so with:" echo echo " git branch --set-upstream-to=$remote/$branch $display_branch_name" echo } exit 1 }