Skip to content

Commit ddfa0fb

Browse files
committed
Merge pull request #3 from connyay/setup
Add setup to script
2 parents cf11471 + e138d6f commit ddfa0fb

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

deploy.sh

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ default_email=
1111
#repository to deploy to. must be readable and writable.
1212
repo=origin
1313

14+
# Parse arg flags
15+
while : ; do
1416
if [[ $1 = "-v" || $1 = "--verbose" ]]; then
15-
verbose=true
17+
verbose=true
18+
shift
19+
elif [[ $1 = "-s" || $1 = "--setup" ]]; then
20+
setup=true
21+
shift
22+
else
23+
break
1624
fi
25+
done
1726

1827
#echo expanded commands as they are executed (for debugging)
1928
function enable_expanded_output {
@@ -31,8 +40,23 @@ function disable_expanded_output {
3140
fi
3241
}
3342

43+
function setup_repo {
44+
mkdir -p $deploy_directory
45+
git --work-tree $deploy_directory checkout --orphan $deploy_branch
46+
git --work-tree $deploy_directory rm -r "*"
47+
git --work-tree $deploy_directory add --all
48+
git --work-tree $deploy_directory commit -m "initial publish"
49+
git push origin $deploy_branch
50+
git symbolic-ref HEAD refs/heads/master && git reset --mixed
51+
}
52+
3453
enable_expanded_output
3554

55+
if [ $setup ]; then
56+
setup_repo
57+
exit
58+
fi
59+
3660
commit_title=`git log -n 1 --format="%s" HEAD`
3761
commit_hash=`git log -n 1 --format="%H" HEAD`
3862

@@ -59,7 +83,7 @@ enable_expanded_output
5983
#make deploy_branch the current branch
6084
git symbolic-ref HEAD refs/heads/$deploy_branch
6185

62-
#put the previously committed contents of deploy_branch branch into the index
86+
#put the previously committed contents of deploy_branch branch into the index
6387
git --work-tree "$deploy_directory" reset --mixed --quiet
6488

6589
git --work-tree "$deploy_directory" add --all
@@ -73,7 +97,7 @@ case $diff in
7397
set_user_id
7498
git --work-tree "$deploy_directory" commit -m \
7599
"publish: $commit_title"$'\n\n'"generated from commit $commit_hash"
76-
100+
77101
disable_expanded_output
78102
#--quiet is important here to avoid outputting the repo URL, which may contain a secret token
79103
git push --quiet $repo $deploy_branch

readme.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,7 @@ Download the script (`wget https://github.com/X1011/git-directory-deploy/raw/mas
1111
- **repo**: repository to deploy to. Must be readable and writable. The default of "origin" will not work on Travis CI, since it uses the read-only git protocol. In that case, it is recommended to store a [GitHub token](https://help.github.com/articles/creating-an-access-token-for-command-line-use) in a [secure environment variable](http://about.travis-ci.org/docs/user/build-configuration/#Secure-environment-variables) and use it in an HTTPS URL like this: <code>repo=https://$GITHUB_TOKEN@github.com/<i>user</i>/<i>repo</i>.git</code>
1212

1313
## setup
14-
Do this once to set up a deploy branch if you don't already have one. This could be implemented in the script, but I don’t feel like doing it. Replace "dist" with your deploy_directory and "gh-pages" with your deploy_branch.
15-
16-
1. `git --work-tree dist checkout --orphan gh-pages`
17-
- this will disconnect the gh-pages branch’s history from the current commit
18-
- in my app, the project root and dist had no files in common. If yours do, be careful if you don’t want to overwrite any existing files in dist
19-
2. `git --work-tree dist rm -r "*"`
20-
- remove the source files we just checked out; these aren’t the files we’re looking for
21-
- the quotes are required to prevent the shell from globbing in the current directory; we want git to glob in dist
22-
3. `git --work-tree dist add --all`
23-
4. `git --work-tree dist commit -m "initial publish"`
24-
5. `git push origin gh-pages`
25-
6. `git symbolic-ref HEAD refs/heads/master && git reset --mixed`
26-
- switch back to master branch
14+
Ensure configuration variables are correct in `deploy.sh` and run `./deploy.sh -s`
2715

2816
## run
2917
Do this every time you want to deploy, or have your CI server do it.

0 commit comments

Comments
 (0)