Recently Written · git

coleslaw

Emacs mode for the "Coleslaw" site generator written in Common Lisp.

git clone https://github.com/equwal/coleslaw

Log | Files | Refs


plugins/publish-gh-pages.sh (1365 bytes)

1 #!/bin/bash -x
2 
3 set -e
4 
5 staging=$1
6 deploy=$2
7 url=$3
8 branch=$4
9 remote=$5
10 cname=$6
11 
12 if [[ -d $deploy && ! -d $deploy/.git ]]
13 then
14    echo "Target directory $deploy exists and is not a git repository. Aborting" >&2
15    exit 1
16 fi
17 
18 if [[ ! -d $deploy ]]
19 then
20     git clone --no-checkout --origin $remote $url $deploy
21 fi
22 
23 cd $deploy
24 
25 # safe and most reliable way to check if the branch exist
26 if git show-ref --verify --quiet refs/heads/$branch
27 then
28     # if the branch exists locally
29     git checkout $branch
30 elif git show-ref --verify --quiet refs/remotes/$remote/$branch
31 then
32     # if the branch does not exist locally but exist in the specified remote ---
33     # Note, git checkout $branch will search the branch with the same name with
34     # ALL remotes, and set it as the tracking branch if there is a single such
35     # remote, but does not allow the user to necessarily specify which.
36     git checkout -b $branch --track $remote/$branch
37 else
38     # if there is no matching branch, make an orphan branch
39     git checkout --orphan $branch
40 fi
41 
42 rsync -avz --delete --exclude .git/ --copy-links $staging $deploy
43 
44 if [[ ! -z "$cname" ]]
45 then
46     echo $cname > CNAME
47 fi
48 
49 git add -A                      # add all changes in the worktree
50 git add $(git ls-files -o )     # add all untracked files in the worktree
51 
52 git commit -m "Deployed on $(date)"
53 
54 git push $remote $branch
55