]>
Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/git-track
4 ## Point the current local branch at <branch> for the purpose
5 ## of merge tracking, pull, and status features. With no <branch>,
6 ## write the currently tracked branch to standard output.
8 ## If you have git's bash-completion support enabled, add this:
9 ## complete -o default -o nospace -F _git_checkout git-track
12 # bail out with message to stderr and exit status 1
14 echo "$(basename $0):" "$@" 1>&2
21 grep '^##' "$0" | cut
-c4-
29 git
rev-parse "$1" >/dev
/null
30 remote
=$(echo "$1" | sed 's@^\(.*\)/.
*@\
1@
')
31 merge=$(echo "$1" | sed 's@^.*/\(.*\)@\1@')
34 git
rev-parse "$1" >/dev
/null
40 # get the current branch in refs/heads/<branch> form
41 ref
=$(git symbolic-ref -q HEAD)
43 die
"you're not on a branch"
45 # just the branch name please
46 branch
=$(echo "$ref" | sed 's@^refs/heads/@@')
48 die
"you're in a weird place; get on a local branch"
50 # if we don't have a target to track, show the
51 # currently tracked stuff.
53 remote
=$(git config --get "branch.$branch.remote" || true)
55 (git config
--get "branch.$branch.merge") |
58 if test -n "$remote" -a -n "$merge"; then
59 echo "$branch -> $remote/$merge"
60 elif test -n "$merge"; then
61 echo "$branch -> $merge"
63 echo "$branch is not tracking anything"
68 # set the remote if a full remote/branch ref was given
70 git config
"branch.$branch.remote" "$remote"
72 # set the ref in said remote we should track
73 git config
"branch.$branch.merge" "refs/heads/$merge"