I'm developing a site in Wordpress that I’ve built a template and a plugin for. For my git workflow, I'd like to be able to track the template and the plugin separately with two different repos on the server. Right now I push template commits into a bare repo on the server, which then executes this post-receive hook:
#!/bin/sh
export GIT_WORK_TREE=/home/user/public_html/wp-content/themes/custom_theme
export GIT_DIR=/home/user/public_html/custom_theme.git
git checkout -f master
And the files show up in the theme folder as intended when I push. But when I tried to set up the exact same thing for the plugin, I get no result. Here is the post-receive hook for the plugin bare repo:
#!/bin/sh
export GIT_WORK_TREE=/home/user/public_html/wp-content/plugins/custom_plugin
export GIT_DIR=/home/user/public_html/custom_plugin.git
git checkout -f master
When I push to the plugin bare repo, the live plugin directory remains empty and I don't even see any error logs. Does this have to do with using two repos on the same server? I tried adding "unset GIT_DIR" at the start of both hooks to see if that made any difference (it didn't). I've also already checked the file permissions and both hooks are executable for all users. Is there at least a way I can run the plugin hook manually and see what the shell response is?
EDIT:
I added the "echo working 1>&2" to the hook to test if it triggers (per torek's suggestion). After committing a test change and pushing to the server bare repo, here is what I got:
stdin: is not a tty
Counting objects: 5, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 376 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Already on 'master'
remote: working
To user#dev.mysite.org:public_html/custom_plugin.git
f1cc0bb..9a71b5b master -> master
So it seems like the hook is triggering right? I'm getting the "remote: working" line of output above. I'm not exactly sure what all of the output means though. Am I missing something there?
Seems to be working just fine now after staring at it for a day.
Related
We frequently use RMarkdown based packages to create websites with R (bookdown, blogdown, distill...) and use github-pages to serve the html files via the url username.github.io/repo.
In this approach, the ouput (i.e. html / css) files are also version controlled, and are frequently included in commits by mistake (git commit -a). This is annoying since these files clutter the commit and often lead to fictitious files conflicts.
Ideally, the outputfiles would not be version controlled at all, since the binary files (images) additionally bloat the repo. So I'm looking for a solution where:
Git ignores the output files completely but provides an alternative (but comparable1) method to gh-pages to serve them
Git ignores the output files temporally and committing / pushing them to gh-pages is done in a separate, explicit command
1: The method should be command line based and provide a nice URL to access the website
You could have .html, .css etc. ignored in the main and all other branches but the branch, for example, the gh-page branch, where your github-page is built from.
Git does not support different .ignore files in different branches so you would have to set up a bash script that replaces the ignore file each time you checkout a new branch. See here for how to do that: https://gist.github.com/wizioo/c89847c7894ede628071
Maybe not the elegant solution you were hoping for but it should work.
If you have a python installation on your computer, you can use GitHub Pages Import, a tool designed specifically for this purpose.
You need a python installation since it has to be installed with pip, but once it's installed it integrates beautifully with into an R / RMarkdown workflow.
Once it's installed (pip install ghp-import), you can run ghp-import docs (assuming docs is where your RMarkdown outputs are stored).
There are a bunch of practical options that you can use, including -p to additionally push the changes to your remote after the commit.
You need to tell Git to ignore the folder the book gets built into.
So, for example, by default bookdown puts all the built files in a folder called "_book"
Just add the following line to the .gitignore file in your project.
_book
Then you can work on your book and build it and push changes without worrying about the site being updated.
To update the site, you want to create a gh-pages branch that is only used for the hosted content. Do that with these commands from in your book folder:
git checkout --orphan gh-pages
git rm -rf .
# create a hidden file .nojekyll
touch .nojekyll
git add .nojekyll
git commit -m"Initial commit"
git push origin gh-pages
Make sure (once you put your book content in that branch) that GitHub is set to use that branch for hosting, rather than the folder you were using before.
Then, you can switch back to your main branch with the following command:
git checkout master
Next, you will clone your gh-pages branch into your main project:
git clone -b gh-pages https://github.com/yourprojecturl.git book-output
Then, when you have a version of the built book (in the _book folder) ready to use as your live site, use the following commands to copy the content into the book-output folder and push that to the gh-pages branch where the live site is:
cd book-output
git rm -rf *
cp -r ../_book/* ./
git add --all *
git commit -m"Update the book"
git push -q origin gh-pages
You can continue to use this last set of commands whenever you have a version in _book that you're ready to push live.
I'm trying to follow the instructions on https://googlecloudplatform.github.io/appengine-php-wordpress-starter-project/. I'm having some doubts at the following step:
The instructions seem to imply that there should be a wp-config.php in the wordpress directory. However, as cloned from Github, there is a wp-config.php in the main directory above that:
whereas the wordpress directory is empty.
I'm considering two options:
1) Edit the wp-config.php and leave it where it is, or
2) Edit the wp-config.php and move it to the wordpress subdirectory.
Would either of these approaches be correct? Also, are there sufficient files in the starter project to initiate Wordpress, or do I perhaps have to download it myself and put the extracted contents in the wordpress directory?
EDIT
Thanks again GAEfan for your answer. I've tried again to clone the Github repository, but the wordpress directory is still empty:
kurt#kurt-ThinkPad:~/Website$ git clone https://github.com/GoogleCloudPlatform/appengine-php-wordpress-starter-project.git
Cloning into 'appengine-php-wordpress-starter-project'...
remote: Counting objects: 575, done.
remote: Total 575 (delta 0), reused 0 (delta 0), pack-reused 575
Receiving objects: 100% (575/575), 79.22 MiB | 11.21 MiB/s, done.
Resolving deltas: 100% (317/317), done.
Checking connectivity... done.
kurt#kurt-ThinkPad:~/Website$ cd app*
kurt#kurt-ThinkPad:~/Website/appengine-php-wordpress-starter-project$ cd wordpress
kurt#kurt-ThinkPad:~/Website/appengine-php-wordpress-starter-project/wordpress$ ls
kurt#kurt-ThinkPad:~/Website/appengine-php-wordpress-starter-project/wordpress$
However, I've noticed that on Github, the wordpress directory is itself a link to another Github project:
I assume I have to clone all the 'submodules' in their respective directories as well?
The wordpress directory should be full of files! Your app.yaml is set up to look there. So, the wp-config.php should be in it, along with many other files.
Try downloading it again. My download was: appengine-php-wordpress-starter-project_build_linux_mac 2
I'm doing development on a Wordpress plugin. My development directory contains a lot of development-specific stuff (e.g. Grunt files, Sass files, the git repository itself, etc.).
Obviously, I don't want to distribute this folder containing all of those development files; people don't want a few MB of Grunt files when they download my Wordpress plugin.
Up until now, though, my "release" process has been cumbersome:
Commit the Git changes
Zip the entire folder
Open the zip file and delete the .git folder, grunt files, and all the other development-specific files
Release the new zip
I don't know the best way to accomplish this, but I'm very vaguely familiar with Git hooks, and I had this thought: could I set up a Git hook that would zip ONLY the needed production files into a ZIP file and store it with the repo? That way, every time I commit it would automatically create a new release ZIP.
Is that possible? If so, could someone point me in the right direction?
Oh also, I'm on Windows (・_・;). So I'm hoping that there's a way to do it on Windows.
I can't speak for Windows, but:
It's technically possible to do that sort of thing in a pre-commit hook.
Don't.
A pre-commit hook that modifies "what you will commit" is annoying (if nothing else, it violates the "rule of least astonishment", where your version control system simply stores the versions you tell it to store). Apart from that, storing large pre-compressed binaries interferes with git's attempt to save space in pack files, and will cause rapid repository bloat, poor performance, running out of memory, and so on. A ZIP-archive is a pre-compressed binary and hence will behave badly.
In general, a more reasonable "hook-y" way to handle releases is to set up a "release server" to which you push new releases, and have the push trigger the archive-generation. (There are ways to do this without a separate server / repository, and you can do it in a more pull-style fashion, but the push-style is easy to illustrate.)
[Edit: I had originally considered git archive but did not realize you could get it to exclude files conveniently, so wrote up the below instead. So, jthill's answer is better and should be one's first resort. I'll leave this in place as an alternative for some case where for some reason, git archive might not do.]
For instance, here's a server-side post-receive hook code fragment that checks whether a branch whose name matches release* has been pushed-to, and if so, invokes a shell function with the name of the branch (once for each such branch):
#! /bin/sh
NULL_SHA1=0000000000000000000000000000000000000000
scan()
{
local oldsha newsha fullref shortref
local optype
while read oldsha newsha fullref; do
case $oldsha,$newsha in
$NULL_SHA1,*) optype=create;;
*,$NULL_SHA1) optype=delete;;
*) optype=update;;
esac
case $fullref in
refs/heads/*)
reftype=branch
shortref=${fullref#refs/heads/}
;;
*)
reftype=other
shortref=fullref
;;
esac
case $optype,$reftype,$shortref in
create,branch,release*|update,branch,release*)
do_release $shortref;;
esac
done
}
scan
(much of the above is boilerplate, which I have stripped down to essentials). You would have to write the do_release function, which might resemble (totally untested):
do_release()
{
local tmpdir=/tmp/build.$$ # or use mktemp -d
# $tmpdir/index is git's index; $tmpdir/t is the work tree
trap "rm -rf $tmpdir; exit 1" 1 2 3 15
rm -rf $tmpdir
mkdir $tmpdir/t
GIT_INDEX_FILE=$tmpdir/index GIT_WORK_TREE=$tmpdir/t git checkout $1
# now clean out grunt files and make zip archive
(cd $workdir/t; rm -rf grunt; zip ../t.zip .)
# put completed zip archive in export location, name it
# based on the branch name
mv $workdir/t.zip /place/where/zip/files/live/$1.zip
# clean up temp dir now, and no longer need to clean up
# on signal related abort
rm -rf $tmpdir
trap - 1 2 3 15
}
There's actually a command for this, git archive.
git archive master -o wizzo-v1.13.0.zip
See the EXAMPLES section, you can select paths, add prefixes to them, define custom postprocessing by output extension, and some more minor tweaks.
Also see the ATTRIBUTES section: you can give files -- arbitrary patterns, really -- an export-ignore attribute to exclude them from archives.
It's got a bunch more handy-dandies, you can get archives from remote repos, expand arbitrary git log --pretty=format: placeholders, the git manpages are definitely worth whatever time you can invest in them.
I'm a relative git newbie, as you're about to see. So please forgive my poor use of git terminology, I'm still learning.
Concise summary of problem: I want to put my local repo on GitHub, but I have some previously-tracked files that are too big.
Background:
This morning I had a local repository where all sorts of files were being tracked: R scripts, .RData files, .csv's, etc. I decided I wanted to make my repository publicly available by pushing it to GitHub.
When I tried to push (using git remote add origin https://github.com/me/repo.git followed by git push -u origin master), I realized that some of my large data files were too large for GitHub. I've decided that it would be OK if the .RData files didn't get pushed to GitHub, and weren't tracked by git (although I don't want to delete the files locally). But I can't figure out how to make this happen.
Things I've tried thus far:
First I added .RData files to the .gitignore file. I quickly realized that
this does nothing for files that are already being tracked.
I used git rm -r --cached . followed by git commit -am "Remove ignored
files", thinking this would help git forget about all of those huge
files I just ignored.
Further following the git help page, I tried git commit --ammend
-CHEAD, but I still couldn't push.
I attempted to use the BFG, but I didn't get very far with it
b/c it apparently didn't find any files larger than 100M. Clearly I
was going something wrong, but decided not to pursue further.
Following some tips I found HERE, I then tried git
filter-branch --tree-filter 'git rm -r -f --ignore-unmatch *.RData'
HEAD. This definitely did something, but I still couldn't push.
However, instead of the huge list of too-big files, I am now down to
2 files that are too big (even though other .RData files in the same
directory are no longer listed).
After my last git push -u origin master --force, this is the print out in terminal:
Counting objects: 1163, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (1134/1134), done.
Writing objects: 100% (1163/1163), 473.07 MiB | 6.80 MiB/s, done.
Total 1163 (delta 522), reused 0 (delta 0)
remote: error: GH001: Large files detected.
remote: error: Trace: 4ce4aa642e458a7a715654ac91c56af4
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File Results/bigFile1.RData is 166.51 MB; this exceeds GitHub's file size limit of 100 M
remote: error: File Results/bigFile2.RData is 166.32 MB; this exceeds GitHub's file size limit of 100 MB
To https://github.com/me/repo.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/me/repo.git'
If you haven't guessed, I don't really know what I'm doing ... I'm essentially trying any code snippet I can find, and seeing if it allows me to push. All of my data and files are backed up, so I'm experimenting rather brazenly.
Given that I'm willing to not track the huge .RData files, how do I get my local repo to the point where I can push it to GitHub?
Any help would be very greatly appreciated. Thanks!
I am pretty sure you will just need to remove them from your .git repo history. Not just remove them from the most current version, they need to be excised from ever having existed in your repo.
The technique is covered elsewhere, see this stackoverflow post or the BFG tool.
I am working on webpage, and I need version tracking, so I'm uploading it to github.
Here is the underlying set up.
https://developers.google.com/appengine/articles/wordpress
Now that I have the base CMS ready to go, I need to get the base code uploaded before I start making changes.
lloydm#lloydm-E6320:~/Downloads/rtt/rtt-code$ pwd
/home/lloydm/Downloads/rtt/rtt-code
lloydm#lloydm-E6320:~/Downloads/rtt/rtt-code$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# wordpress/
nothing added to commit but untracked files present (use "git add" to track)
lloydm#lloydm-E6320:~/Downloads/rtt/rtt-code$ ls
app.yaml cron.yaml php.ini wordpress
lloydm#lloydm-E6320:~/Downloads/rtt/rtt-code$ git add .
fatal: Not a git repository: wordpress/wp-content/plugins/../.git/modules/appengine-wordpress-plugin
I've never used github before, so I was just following the github website stuff. I have zero idea what this error means or how to prevent it. I can't find anything that I think is related to it.
You need to set up your git repo correctly.
I think you followed this section "Installing WordPress on your development environment" from the link you provided https://developers.google.com/appengine/articles/wordpress
So what you did was download WordPress into your folder which you set up to be a .git repository. However, the WordPress project builder you downloaded itself contains a .git repository.
Check if you have a /workpress/.git file. It likely contains something like :
gitdir: ../.git/modules/wordpress
If you do, then that explains the error I think.
As for setting it up correctly, there are many tutorials available.
One way is to use Git for theme deployment, rather than having it manage your entire WordPress installation --> http://culttt.com/2013/04/08/how-to-deploy-wordpress-themes-with-git/
Another way is to add wordpress as a submodule http://www.efeqdev.com/website-development/this-is-how-we-version-control-and-deploy-our-wordpress-websites-with-git/
or Just make a ~/Downloads/rtt/rtt-code/wordpress/myWebpage directory and set up a git repo in it. http://www.whistlenet.com/git-for-wordpress/
I think you just need to go into the wordpress folder and then run the git status command. As the directory(rtt-code) is not a git directory but contains within it the git repo, that is wordpress, you are getting this error.
Inside the wordpress folder, all your git commands would work perfectly well...