Thursday, March 24, 2011

Exporting files from hook in bare git repository

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.

From stackoverflow
  • (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.

    alt text


    Less complicated: Using Git to maintain your website:

    alt text


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

  • 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

    jeeger : That sounds good, i'm gonna try that. The only question is how to get the sha hash.
    jeeger : 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?
    Pieter : try using HEAD:HTML instead "HEAD HTML"
    VonC : 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 ;)

0 comments:

Post a Comment