Junio C Hamano | ac4b0cf | 2005-08-20 02:52:24 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Junio C Hamano | e8cc80d | 2005-11-23 23:46:13 -0800 | [diff] [blame] | 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. |
Dan Loewenherz | 7bd93c1 | 2009-04-22 21:46:02 -0400 | [diff] [blame] | 5 | GIT_DIR=$(git rev-parse -q --git-dir) || :; |
Junio C Hamano | ac4b0cf | 2005-08-20 02:52:24 -0700 | [diff] [blame] | 6 | |
Santi Béjar | 648ad18 | 2006-09-23 12:05:43 +0200 | [diff] [blame] | 7 | get_default_remote () { |
Stephen Boyd | 9ecd3ad | 2011-03-30 01:48:40 -0700 | [diff] [blame] | 8 | curr_branch=$(git symbolic-ref -q HEAD) |
Junio C Hamano | 2352570 | 2011-03-30 19:33:33 -0700 | [diff] [blame] | 9 | curr_branch="${curr_branch#refs/heads/}" |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 10 | origin=$(git config --get "branch.$curr_branch.remote") |
Santi Béjar | 648ad18 | 2006-09-23 12:05:43 +0200 | [diff] [blame] | 11 | echo ${origin:-origin} |
| 12 | } |
| 13 | |
Santi Béjar | 97af7ff | 2009-06-12 00:39:18 +0200 | [diff] [blame] | 14 | get_remote_merge_branch () { |
| 15 | case "$#" in |
| 16 | 0|1) |
Santi Béjar | e9460a6 | 2009-06-12 00:39:19 +0200 | [diff] [blame] | 17 | origin="$1" |
| 18 | default=$(get_default_remote) |
| 19 | test -z "$origin" && origin=$default |
Santi Béjar | f864f26 | 2010-12-06 11:20:11 +0100 | [diff] [blame] | 20 | curr_branch=$(git symbolic-ref -q HEAD) && |
Santi Béjar | e9460a6 | 2009-06-12 00:39:19 +0200 | [diff] [blame] | 21 | [ "$origin" = "$default" ] && |
| 22 | echo $(git for-each-ref --format='%(upstream)' $curr_branch) |
| 23 | ;; |
Santi Béjar | 97af7ff | 2009-06-12 00:39:18 +0200 | [diff] [blame] | 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 |
Martin von Zweigbergk | fe249b4 | 2010-11-13 23:58:22 +0100 | [diff] [blame] | 43 | [ -n "$remote" ] && case "$repo" in |
| 44 | .) |
| 45 | echo "refs/heads/$remote" |
| 46 | ;; |
| 47 | *) |
| 48 | echo "refs/remotes/$repo/$remote" |
| 49 | ;; |
| 50 | esac |
Santi Béjar | 97af7ff | 2009-06-12 00:39:18 +0200 | [diff] [blame] | 51 | esac |
| 52 | } |
Martin von Zweigbergk | 15a147e | 2011-02-09 20:54:02 -0500 | [diff] [blame] | 53 | |
| 54 | error_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) |
| 60 | if test -z "$branch_name" |
| 61 | then |
| 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." |
| 67 | else |
| 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. |
| 74 | |
| 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/}\"] |
| 78 | remote = <nickname> |
| 79 | merge = <remote-ref>" |
| 80 | test rebase = "$op_type" && |
| 81 | echo " rebase = true" |
| 82 | echo " |
| 83 | [remote \"<nickname>\"] |
| 84 | url = <url> |
| 85 | fetch = <refspec> |
| 86 | |
| 87 | See git-config(1) for details." |
| 88 | fi |
| 89 | exit 1 |
| 90 | } |