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 |
sed -e 's|^refs/heads/||')
9 origin
=$
(git config
--get "branch.$curr_branch.remote")
10 echo ${origin:-origin}
13 get_remote_merge_branch
() {
17 default
=$
(get_default_remote
)
18 test -z "$origin" && origin
=$default
19 curr_branch
=$
(git symbolic-ref
-q HEAD
) &&
20 [ "$origin" = "$default" ] &&
21 echo $
(git for-each-ref
--format='%(upstream)' $curr_branch)
27 # FIXME: It should return the tracking branch
28 # Currently only works with the default mapping
31 ref
=$
(expr "z$ref" : 'z+\(.*\)')
34 expr "z$ref" : 'z.*:' >/dev
/null || ref
="${ref}:"
35 remote
=$
(expr "z$ref" : 'z\([^:]*\):')
37 '' | HEAD
) remote
=HEAD
;;
38 heads
/*) remote
=${remote#heads/} ;;
39 refs
/heads
/*) remote
=${remote#refs/heads/} ;;
40 refs
/* | tags
/* | remotes
/* ) remote
=
42 [ -n "$remote" ] && case "$repo" in
44 echo "refs/heads/$remote"
47 echo "refs/remotes/$repo/$remote"
53 error_on_missing_default_upstream
() {
58 branch_name
=$
(git symbolic-ref
-q HEAD
)
59 if test -z "$branch_name"
61 echo "You are not currently on a branch, so I cannot use any
62 'branch.<branchname>.merge' in your configuration file.
63 Please specify which branch you want to $op_type $op_prep on the command
64 line and try again (e.g. '$example').
65 See git-${cmd}(1) for details."
67 echo "You asked me to $cmd without telling me which branch you
68 want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in
69 your configuration file does not tell me, either. Please
70 specify which branch you want to use on the command line and
71 try again (e.g. '$example').
72 See git-${cmd}(1) for details.
74 If you often $op_type $op_prep the same branch, you may want to
75 use something like the following in your configuration file:
76 [branch \"${branch_name#refs/heads/}\"]
79 test rebase
= "$op_type" &&
82 [remote \"<nickname>\"]
86 See git-config(1) for details."