]> git.phdru.name Git - git-scripts.git/blob - detached-head/fix-detached-head
Feat(fix-detached-head): Get branch from superproject
[git-scripts.git] / detached-head / fix-detached-head
1 #! /usr/bin/env bash
2
3 git symbolic-ref -q HEAD >/dev/null && exit
4
5 pwd
6
7 declare -a branches
8 branches=(`git branch --points-at=HEAD | tail -n +2`)
9
10 if [ "${#branches[*]}" -eq 0 ]; then
11    branches=(`git config -f $toplevel/.gitmodules --get submodule.$name.branch`)
12 fi
13
14 if [ "${#branches[*]}" -eq 0 ]; then
15    branches=(`git branch --points-at=HEAD -r | sed 's!^ *origin/!!'`)
16 fi
17
18 if [ "${#branches[*]}" -eq 0 ]; then
19    echo "Cannot find a branch" >&2
20 elif [ "${#branches[*]}" -eq 1 ]; then
21    git checkout "${branches[0]}"
22 else
23    echo "Too many branches" >&2
24 fi