]> git.ipfire.org Git - thirdparty/git.git/blame - git-parse-remote.sh
GIT-VERSION-GEN: support non-standard $GIT_DIR path
[thirdparty/git.git] / git-parse-remote.sh
CommitLineData
ac4b0cff
JH
1#!/bin/sh
2
e8cc80d0
JH
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.
7bd93c1c 5GIT_DIR=$(git rev-parse -q --git-dir) || :;
ac4b0cff 6
648ad18f 7get_default_remote () {
9ecd3ada 8 curr_branch=$(git symbolic-ref -q HEAD)
2352570b 9 curr_branch="${curr_branch#refs/heads/}"
5be60078 10 origin=$(git config --get "branch.$curr_branch.remote")
648ad18f
SB
11 echo ${origin:-origin}
12}
13
97af7ff0
SB
14get_remote_merge_branch () {
15 case "$#" in
16 0|1)
e9460a66
SB
17 origin="$1"
18 default=$(get_default_remote)
19 test -z "$origin" && origin=$default
f864f261 20 curr_branch=$(git symbolic-ref -q HEAD) &&
e9460a66
SB
21 [ "$origin" = "$default" ] &&
22 echo $(git for-each-ref --format='%(upstream)' $curr_branch)
23 ;;
97af7ff0
SB
24 *)
25 repo=$1
26 shift
27 ref=$1
28 # FIXME: It should return the tracking branch
29 # Currently only works with the default mapping
30 case "$ref" in
31 +*)
32 ref=$(expr "z$ref" : 'z+\(.*\)')
33 ;;
34 esac
35 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
36 remote=$(expr "z$ref" : 'z\([^:]*\):')
37 case "$remote" in
38 '' | HEAD ) remote=HEAD ;;
39 heads/*) remote=${remote#heads/} ;;
40 refs/heads/*) remote=${remote#refs/heads/} ;;
41 refs/* | tags/* | remotes/* ) remote=
42 esac
fe249b42
MZ
43 [ -n "$remote" ] && case "$repo" in
44 .)
45 echo "refs/heads/$remote"
46 ;;
47 *)
48 echo "refs/remotes/$repo/$remote"
49 ;;
50 esac
97af7ff0
SB
51 esac
52}
15a147e6
MZ
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)
3c02396a
CMN
60 # If there's only one remote, use that in the suggestion
61 remote="<remote>"
62 if test $(git remote | wc -l) = 1
63 then
64 remote=$(git remote)
65 fi
66
15a147e6
MZ
67 if test -z "$branch_name"
68 then
3c02396a
CMN
69 echo "You are not currently on a branch. Please specify which
70branch you want to $op_type $op_prep. See git-${cmd}(1) for details.
71
72 $example
73"
15a147e6 74 else
3c02396a
CMN
75 echo "There is no tracking information for the current branch.
76Please specify which branch you want to $op_type $op_prep.
77See git-${cmd}(1) for details
78
79 $example
15a147e6 80
3c02396a 81If you wish to set tracking information for this branch you can do so with:
15a147e6 82
a3a4391a 83 git branch --set-upstream-to=$remote/<branch> ${branch_name#refs/heads/}
3c02396a 84"
15a147e6
MZ
85 fi
86 exit 1
87}