Skip to content

Commit 8dae956

Browse files
committed
handle detached HEAD with new branch switching commands
1 parent 9f58b2c commit 8dae956

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

deploy.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ set_user_id() {
2121
}
2222

2323
previous_branch=`git rev-parse --abbrev-ref HEAD`
24-
if [[ $previous_branch = "HEAD" ]]; then
25-
previous_branch=$commit_hash
26-
fi
2724

2825
if ! git diff --exit-code --quiet --cached; then
2926
echo Aborting due to uncommitted changes in the index
@@ -47,5 +44,11 @@ else
4744
git push origin $deploy_branch
4845
fi
4946

50-
git symbolic-ref HEAD refs/heads/$previous_branch
47+
if [[ $previous_branch = "HEAD" ]]; then
48+
#we weren't on any branch before, so just set HEAD back to the commit it was on
49+
git update-ref --no-deref HEAD $commit_hash $deploy_branch
50+
else
51+
git symbolic-ref HEAD refs/heads/$previous_branch
52+
fi
53+
5154
git reset --mixed

0 commit comments

Comments
 (0)