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