7

So, my situation is the following: I want to maintain my website using emacs-muse mode. For transferring the website (and version control), I want to use git. So I would create a hook in the remote (bare) repository that automatically copies the HTML subdir to the web directory. How can I do that from a hook? Also note that the whole directory contains a lot of files, so I can't export the whole directory.

Any help welcome.

jeeger
  • 133
  • 2
  • 5

2 Answers2

15

You can use git archive, as it takes a path command. So, in your post-update hook you can do something like

git archive $SHA HTML | (cd dir/where/html/should/go && tar x)

this first creates a tarball of the subdir, and pipes that tarball to a tar command to untar it in the specified directory

Pieter
  • 4,010
  • 1
  • 18
  • 15
  • That sounds good, i'm gonna try that. The only question is how to get the sha hash. – jeeger Jan 20 '09 at 14:47
  • Okay, archieving HEAD works. However, archive saves "absolute" paths in relation to the git repository. However, I want to extract the files and cut the path components. How would I do that? – jeeger Jan 20 '09 at 15:53
  • 3
    try using HEAD:HTML instead "HEAD HTML" – Pieter Jan 20 '09 at 17:11
  • 4
    That is odd: your answer seems to be more specific and fits better jeeger's question, yet mine has more vote: +1 to fix that ;) – VonC Jan 20 '09 at 17:54
14

(just a suggestion, as it may not be applicable in your exact configuration)

You might consider adopting this Web-Focused Git Workflow which, instead of copying, does push your repo directly on the web directory.

http://joemaller.com/wordpress/wp-content/uploads/2008/11/hub-prime2.jpg
(From Joe MALLER)


Less complicated: Using Git to maintain your website (Daniel MIESSLER):

http://dmiessler.com/wp-content/uploaded_content/2008/12/git-tree.gif

Daniel MIESSLER has an updated version of that same process:

http://danielmiessler.com/wp-content/uploads/2011/07/git_website_1.png

Other suggestions are available at this SO question, like this post-update script mentioned in the Git FAQ.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Link to post-update script got stale in the funniest way: If I have to do fitness exercises every time I want to go through post-upgrade, I'll win the next election for governor of California ;-) – cfi Oct 08 '15 at 06:26
  • @cfi Thank you. I have restored the link. – VonC Oct 08 '15 at 06:51