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) ||
:;
7 get_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")
11 echo ${origin:-origin}
14 get_remote_merge_branch
() {
18 default
=$
(get_default_remote
)
19 test -z "$origin" && origin
=$default
20 curr_branch
=$
(git symbolic-ref
-q HEAD
) &&
21 [ "$origin" = "$default" ] &&
22 echo $
(git for-each-ref
--format='%(upstream)' $curr_branch)
28 # FIXME: It should return the tracking branch
29 # Currently only works with the default mapping
32 ref
=$
(expr "z$ref" : 'z+\(.*\)')
35 expr "z$ref" : 'z.*:' >/dev
/null || ref
="${ref}:"
36 remote
=$
(expr "z$ref" : 'z\([^:]*\):')
38 '' | HEAD
) remote
=HEAD
;;
39 heads
/*) remote
=${remote#heads/} ;;
40 refs
/heads
/*) remote
=${remote#refs/heads/} ;;
41 refs
/* | tags
/* | remotes
/* ) remote
=
43 [ -n "$remote" ] && case "$repo" in
45 echo "refs/heads/$remote"
48 echo "refs/remotes/$repo/$remote"
54 error_on_missing_default_upstream
() {
59 branch_name
=$
(git symbolic-ref
-q HEAD
)
60 if test -z "$branch_name"
62 echo "You are not currently on a branch, so I cannot use any
63 'branch.<branchname>.merge' in your configuration file.
64 Please specify which branch you want to $op_type $op_prep on the command
65 line and try again (e.g. '$example').
66 See git-${cmd}(1) for details."
68 echo "You asked me to $cmd without telling me which branch you
69 want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in
70 your configuration file does not tell me, either. Please
71 specify which branch you want to use on the command line and
72 try again (e.g. '$example').
73 See git-${cmd}(1) for details.
75 If you often $op_type $op_prep the same branch, you may want to
76 use something like the following in your configuration file:
77 [branch \"${branch_name#refs/heads/}\"]
80 test rebase
= "$op_type" &&
83 [remote \"<nickname>\"]
87 See git-config(1) for details."