THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.6KB

  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.
  4. # git-ls-remote could be called from outside a git managed repository;
  5. # this would fail in that case and would issue an error message.
  6. 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}
  12. }
  13. get_remote_merge_branch () {
  14. case "$#" in
  15. 0|1)
  16. origin="$1"
  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)
  22. ;;
  23. *)
  24. repo=$1
  25. shift
  26. ref=$1
  27. # FIXME: It should return the tracking branch
  28. # Currently only works with the default mapping
  29. case "$ref" in
  30. +*)
  31. ref=$(expr "z$ref" : 'z+\(.*\)')
  32. ;;
  33. esac
  34. expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
  35. remote=$(expr "z$ref" : 'z\([^:]*\):')
  36. case "$remote" in
  37. '' | HEAD ) remote=HEAD ;;
  38. heads/*) remote=${remote#heads/} ;;
  39. refs/heads/*) remote=${remote#refs/heads/} ;;
  40. refs/* | tags/* | remotes/* ) remote=
  41. esac
  42. [ -n "$remote" ] && case "$repo" in
  43. .)
  44. echo "refs/heads/$remote"
  45. ;;
  46. *)
  47. echo "refs/remotes/$repo/$remote"
  48. ;;
  49. esac
  50. esac
  51. }
  52. error_on_missing_default_upstream () {
  53. cmd="$1"
  54. op_type="$2"
  55. op_prep="$3" # FIXME: op_prep is no longer used
  56. example="$4"
  57. branch_name=$(git symbolic-ref -q HEAD)
  58. display_branch_name="${branch_name#refs/heads/}"
  59. # If there's only one remote, use that in the suggestion
  60. remote="$(gettext "<remote>")"
  61. branch="$(gettext "<branch>")"
  62. if test $(git remote | wc -l) = 1
  63. then
  64. remote=$(git remote)
  65. fi
  66. if test -z "$branch_name"
  67. then
  68. gettextln "You are not currently on a branch."
  69. else
  70. gettextln "There is no tracking information for the current branch."
  71. fi
  72. case "$op_type" in
  73. rebase)
  74. gettextln "Please specify which branch you want to rebase against."
  75. ;;
  76. merge)
  77. gettextln "Please specify which branch you want to merge with."
  78. ;;
  79. *)
  80. echo >&2 "BUG: unknown operation type: $op_type"
  81. exit 1
  82. ;;
  83. esac
  84. eval_gettextln "See git-\${cmd}(1) for details."
  85. echo
  86. echo " $example"
  87. echo
  88. if test -n "$branch_name"
  89. then
  90. gettextln "If you wish to set tracking information for this branch you can do so with:"
  91. echo
  92. echo " git branch --set-upstream-to=$remote/$branch $display_branch_name"
  93. echo
  94. fi
  95. exit 1
  96. }