Git sparse-checkout on a remote with a post-receive script
Asked Answered
I

1

6

I'm trying to figure out how to do the following (and figure out if it's even possible).

I have a local git repo with a number of folders for various things, but I want to be able to deploy my website with git to my development server and really only the contents of one folder should go into the remote webroot (just the content of the folder, not the folder itself, that's the tough bit). I have the git push to the dev server going into a bare repo outside of the web accessible folders, and then I am using a post-receive script to place all the working files into the webroot. However, this copies all the folders and obviously I only want the contents of one specific folder to move after the operation is completed.

Doing some research, it looks like sparse-checkout would be a good fit. UPDATE: I have it working now where it will copy just a specific folder, but I still haven't gotten it to ignore the folder itself and just pull the contents. I figure this is something having to do with the paths/wildcards I add to .git/info/sparse-checkout, but I'm not sure what the pattern is for excluding a directory but not excluding its contents.

Is there a good way to do this? Should I just use the post-receive script to manually copy the contents of the directory I want rather than trying to do it directly using sparse checkout?

I am grateful for any help anyone is willing to give. Thanks!

Inaudible answered 8/8, 2012 at 20:35 Comment(1)
After reviewing it further, I believe you can't pull content OUT of a directory using sparse-checkout. You can cherry pick things inside of a directory, but the directory structure seems to stay intact no matter what you do. I found a way that works for me in my situation, but please if anybody figures out how to do this respond to this thread. Thanks!Inaudible
N
1

A simpler approach would be to:

  • do the sparse checkout in a /tmp/YourRepo/Yourdirectory (with YourDirectory being the one you are trying to ignore, since only its content is of interest)
  • move the content of /tmp/Yourdirectory over to the right target directory
Nugent answered 9/8, 2012 at 6:27 Comment(1)
I thought about that, but I thought there might be some speed benefit from checkout out directly to the webroot, though I might just be thinking about it incorrectly. If I have a collection of files in the webroot already and I update to that same location, wouldn't I just be updating the files that had changed in the webroot from the commit, or am I basically doing a full tree copy with the post-receive hook anyway? (GIT_WORK_TREE=/my/directory). I assume if I go to /tmp I'd always be doing a full tree copy rather than just updating the files that had changed?Inaudible

© 2022 - 2024 — McMap. All rights reserved.