Skip to content

Commit 0679413

Browse files
committed
more robust setup
1 parent ac26812 commit 0679413

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

deploy.sh

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ function set_user_id {
5151
fi
5252
}
5353

54+
function restore_head {
55+
if [[ $previous_branch = "HEAD" ]]; then
56+
#we weren't on any branch before, so just set HEAD back to the commit it was on
57+
git update-ref --no-deref HEAD $commit_hash $deploy_branch
58+
else
59+
git symbolic-ref HEAD refs/heads/$previous_branch
60+
fi
61+
62+
git reset --mixed
63+
}
64+
5465
commit_title=`git log -n 1 --format="%s" HEAD`
5566
commit_hash=`git log -n 1 --format="%H" HEAD`
5667
previous_branch=`git rev-parse --abbrev-ref HEAD`
@@ -60,9 +71,9 @@ if [ $setup ]; then
6071
git --work-tree $deploy_directory checkout --orphan $deploy_branch
6172
git --work-tree $deploy_directory rm -r "*"
6273
git --work-tree $deploy_directory add --all
63-
git --work-tree $deploy_directory commit -m "initial publish"
64-
git push origin $deploy_branch
65-
git symbolic-ref HEAD refs/heads/master && git reset --mixed
74+
git --work-tree $deploy_directory commit -m "initial publish"$'\n\n'"generated from commit $commit_hash"
75+
git push $repo $deploy_branch
76+
restore_head
6677
exit
6778
fi
6879

@@ -104,11 +115,4 @@ case $diff in
104115
;;
105116
esac
106117

107-
if [[ $previous_branch = "HEAD" ]]; then
108-
#we weren't on any branch before, so just set HEAD back to the commit it was on
109-
git update-ref --no-deref HEAD $commit_hash $deploy_branch
110-
else
111-
git symbolic-ref HEAD refs/heads/$previous_branch
112-
fi
113-
114-
git reset --mixed
118+
restore_head

0 commit comments

Comments
 (0)