1 | #!/usr/bin/env bash
|
2 | set -e
|
3 |
|
4 | DOCS_PATH=.git/groc-tmp
|
5 | TARGET_BRANCH=gh-pages
|
6 | TARGET_REMOTE=origin
|
7 |
|
8 |
|
9 |
|
10 | exec_git() {
|
11 | args=''
|
12 | for (( i = 1; i <= $#; i++ )); do
|
13 | eval arg=\$$i
|
14 | if [[ $arg == *\ * ]]; then
|
15 |
|
16 | args="$args \"$arg\""
|
17 | else
|
18 | args="$args $arg"
|
19 | fi
|
20 | done
|
21 |
|
22 | set +e
|
23 |
|
24 | result=`eval git $args 2>&1`
|
25 | status=$?
|
26 | set -e
|
27 |
|
28 | if [[ $status -ne 0 ]]; then
|
29 | echo "$result" >&2
|
30 | exit $status
|
31 | fi
|
32 |
|
33 | echo "$result"
|
34 | return 0
|
35 | }
|
36 |
|
37 | if [[ `git status -s` != "" ]]; then
|
38 | echo "Please commit or stash your changes before publishing documentation to github!" >&2
|
39 | exit 1
|
40 | fi
|
41 |
|
42 | CURRENT_BRANCH=`git branch 2>/dev/null| sed -n '/^\*/s/^\* //p'`
|
43 | CURRENT_COMMIT=`git rev-parse HEAD`
|
44 |
|
45 |
|
46 | if [[ -e .gitignore ]]; then
|
47 | cp .gitignore $DOCS_PATH/
|
48 | fi
|
49 |
|
50 | if [[ `git branch --no-color | grep " $TARGET_BRANCH"` == "" ]]; then
|
51 |
|
52 | exec_git fetch $TARGET_REMOTE
|
53 |
|
54 |
|
55 | if [[ `git branch -a --no-color | grep " remotes/$TARGET_REMOTE/$TARGET_BRANCH"` == "" ]]; then
|
56 | echo "No '$TARGET_BRANCH' branch exists. Creating one"
|
57 | exec_git symbolic-ref HEAD refs/heads/$TARGET_BRANCH
|
58 | rm .git/index
|
59 |
|
60 |
|
61 | if [[ -e $DOCS_PATH/.gitignore ]]; then
|
62 | cp $DOCS_PATH/.gitignore .gitignore
|
63 | exec_git add .gitignore
|
64 | fi
|
65 |
|
66 | exec_git clean -fdq
|
67 | else
|
68 | echo "No local branch '$TARGET_BRANCH', checking out 'origin/$TARGET_BRANCH' and tracking that"
|
69 | exec_git checkout -b $TARGET_BRANCH $TARGET_REMOTE/$TARGET_BRANCH
|
70 | fi
|
71 |
|
72 | else
|
73 | exec_git checkout $TARGET_BRANCH
|
74 | fi
|
75 |
|
76 |
|
77 | exec_git ls-files | xargs rm
|
78 |
|
79 | cp -Rf $DOCS_PATH/* .
|
80 | if [[ -e $DOCS_PATH/.gitignore ]]; then
|
81 | cp $DOCS_PATH/.gitignore .gitignore
|
82 | fi
|
83 |
|
84 |
|
85 | if [[ `git status -s` != "" ]]; then
|
86 | exec_git add -A
|
87 | exec_git commit -m "Generated documentation for $CURRENT_COMMIT"
|
88 | exec_git push origin $TARGET_BRANCH
|
89 | fi
|
90 |
|
91 |
|
92 | rm -rf $DOCS_PATH
|
93 |
|
94 | exec_git checkout $CURRENT_BRANCH
|