From 23258c90505f38c34224e3265dcec8881be7fcf3 Mon Sep 17 00:00:00 2001 From: Robert Hansel Date: Mon, 14 Dec 2020 23:46:33 +0100 Subject: [PATCH] Support for main and master branch (PR #7) - Adds command to check master/main branch name. - Print the name of the default branch. Co-authored-by: Manoel Campos --- entrypoint.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4612133..feeb3be 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,13 +20,23 @@ git config --local user.email "action@github.com" git config --local user.name "GitHub Action" +# Taking care of the fact that GitHub repos can have a default +# branch which can either be named master or main + +default_branch="master" +if ! git show-branch --list $default_branch; then + default_branch="main" +fi +echo "Default branch: $default_branch" + # Avoids keeping the commit history for the gh-pages branch, # so that such a branch keeps only the last commit. # But this slows down the GitHub Pages website build process. echo "Checking out the gh-pages branch without keeping its history" git branch -D gh-pages 1>/dev/null 2>/dev/null || true git log | head -n 1 | cut -d' ' -f2 > /tmp/commit-hash.txt -git checkout -q --orphan gh-pages master 1>/dev/null +git fetch --all +git checkout -q --orphan gh-pages $default_branch 1>/dev/null #echo "Checking out the gh-pages branch, keeping its history" #git checkout master -B gh-pages 1>/dev/null