1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-08 14:46:11 +02:00
git/git-parse-remote.sh
Junio C Hamano 17a0299807 Merge branch 'maint'
* maint:
  contrib/thunderbird-patch-inline: do not require bash to run the script
  t8001: check the exit status of the command being tested
  strbuf.h: remove a tad stale docs-in-comment and reference api-doc instead
  Typos: t/README
  Documentation/config.txt: make truth value of numbers more explicit
  git-pack-objects.txt: fix grammatical errors
  parse-remote: replace unnecessary sed invocation
2011-03-30 14:10:41 -07:00

53 lines
1.3 KiB
Bash

#!/bin/sh
# git-ls-remote could be called from outside a git managed repository;
# this would fail in that case and would issue an error message.
GIT_DIR=$(git rev-parse -q --git-dir) || :;
get_default_remote () {
curr_branch=$(git symbolic-ref -q HEAD)
curr_branch="${cur_branch#refs/heads/}"
origin=$(git config --get "branch.$curr_branch.remote")
echo ${origin:-origin}
}
get_remote_merge_branch () {
case "$#" in
0|1)
origin="$1"
default=$(get_default_remote)
test -z "$origin" && origin=$default
curr_branch=$(git symbolic-ref -q HEAD) &&
[ "$origin" = "$default" ] &&
echo $(git for-each-ref --format='%(upstream)' $curr_branch)
;;
*)
repo=$1
shift
ref=$1
# FIXME: It should return the tracking branch
# Currently only works with the default mapping
case "$ref" in
+*)
ref=$(expr "z$ref" : 'z+\(.*\)')
;;
esac
expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
remote=$(expr "z$ref" : 'z\([^:]*\):')
case "$remote" in
'' | HEAD ) remote=HEAD ;;
heads/*) remote=${remote#heads/} ;;
refs/heads/*) remote=${remote#refs/heads/} ;;
refs/* | tags/* | remotes/* ) remote=
esac
[ -n "$remote" ] && case "$repo" in
.)
echo "refs/heads/$remote"
;;
*)
echo "refs/remotes/$repo/$remote"
;;
esac
esac
}