3

I'm setting up a git repository for a website on a GoDaddy shared hosting account. Normally one would set up a git bare repo on the server that contained the live web data only, then on a push to the remote use a git post-receive hook to checkout to the live directory (thanks to @VonC for the links).

That's fine, but I've set up the repository to include work files as well. On the server I have,

/home/username/repo.git/work_folders, and /home/username/repo/web_files_and_folders

for the repository, and,

/home/username/public_html/web_files_and_folders

for the live files and folders.

The work_folders usually contain svg, png and jpg files used to generate the png and jpg files for the website. These are master files which are part of the development of the website.

The thing is I can't find an easy way to get git to checkout the web_files_and_folders only to live from any given branch. I could use the shell to wildcard select the web_files_and_folders but that doesn't solve knowing the branch name (which could change of course with each branch).

Do I need to merge to master (for instance) and then do the shell wildcard in the post-receive hook? If so, that may be a problem for other less tech savy people I'm trying to get to use the repo.

EDIT -------------------

So, to update. From a terminal shell I entered,

GIT_WORK_TREE=/home/user/public_html/dev git checkout -f dev devpath/web/*

which extracted the right files from the web folder but rather than getting,

/home/user/public_html/dev/*

I got,

/home/user/public_html/dev/devpath/web/*

Evidently I'm missing something about how to change the extract path.

EDIT 2 -------------------

Ok, more detail...

I currently have a bare repo setup on a shared server at,

/home/user/repo.git

The local repository has 2 branches, dev and master, with a file format like,

/devpath/logos/
/devpath/photos/
...
/devpath/web/  (website root files and folders)

The idea is to develop in the dev branch, push to the server and test on the dev.url of the website, and when things are good merge the dev branch into the master, push to the server and go live. Currently 2 of us are developing the website.

The post-receive hook isn't completed yet but is similar to this one. My use is pretty much the same as this link except I want the remote repository to store the other development files. These files are part of the website development and need to be shared.

What you saw in my first edit was an attempt to checkout the dev branch to the dev test site. On the server this test site is a subdomain and is accessed as a folder under the public html root in the filesystem.

It looks to me like checking out with a wildcard selector,

GIT_WORK_TREE=/home/user/public_html/dev git checkout -f dev devpath/web/*

also puts the files under that same path prior to the wildcard. I need to be able to define a new default path.

I have Git 1.7.1 on the server.

Community
  • 1
  • 1
  • Just to be sure, where is your bare repo (a `repo.git` folder)? Because you cannot or shouldn't push to a non-bare repo. – VonC Jun 24 '14 at 05:29
  • Right. It is a bare repo. I changed the repo name above to reflect that the repo is bare -- though, of course, naming alone doesn't do that. –  Jun 24 '14 at 14:59
  • Please tell us the bigger picture of what you are trying to achieve. The above feels like half a solution that doesn't work. Tell us the bigger goal - maybe it is having untracked files within the repository? something else? We will be much more likely to suggest a good approach for you. – Michael Durrant Jul 01 '14 at 23:56

2 Answers2

0

that doesn't solve knowing the branch name

Regarding that, a post-update hook can detect the branch being pushed.
See:

Something like:

#!/bin/bash

while read oldrev newrev ref
do
  branch=`echo $ref | cut -d/ -f3`

  if [ "master" == "$branch" ]; then
    ....
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm currently trying the commit from a shell to work out selecting out the files I need. It works, except it retains the path info in the repo. See my edit above for details. It must be a simple fix but it's evading me. –  Jul 01 '14 at 23:57
0

Solve this with plumbing:

GIT_WORK_TREE=deploy/path GIT_INDEX_FILE=manifest/path \
        git read-tree -um commit:web_files_and_folders
jthill
  • 55,082
  • 5
  • 77
  • 137
  • I tried, `GIT_WORK_TREE=/home/user/public_html/dev GIT_INDEX_FILE=/home/user/repo.git git read-tree -um \ commit:devpath/web/\*` Did I interpret this right? Using this code I get, `fatal: Out of memory? mmap failed: No such device` –  Jul 02 '14 at 02:35
  • Did the code above come from the documentation at all? –  Jul 02 '14 at 04:25
  • 1
    That "manifest path" is to an arbitrary you-name-it flat file, use e.g. `GIT_INDEX_FILE=/home/user/repo.git/info/public_html-dev.manifest` -- that's all the index is, a manifest, a worktree-path-indexed list of thumbs into the object db. Also, just in case, the backslash+linebreak is literal, it's shell continuation-line syntax. @Cupcake no, it's just straightforward read-tree usage is all, and btw re your formatting edit, what browser are you using that fails so miserably? – jthill Jul 02 '14 at 11:29
  • @jthill I'm using Chrome. Your answer contained a bunch of [unnecessary markup](http://stackoverflow.com/revisions/81ea018c-7f0b-470d-bfd3-9d23c896f853/view-source), which made the formatting look really out of place. –  Jul 02 '14 at 17:07
  • @Cupcake That's bizarre, I'm on Chrome and it renders perfectly for me -- in particular, markdown generates _identical_ html for `_\`commit\`_\`:\`_\`path\`_` except only for embedded, unnecessary, and incorrect `` pairs surrounding the `` tags -- incorrect because the `` spans render with margins indistinguishable from (invalid) spaces in the text. Syntax diagrams in doc use italics to render nonterminals and I think that's by far the clearest way to show most code/command examples. – jthill Jul 02 '14 at 17:49
  • @Cupcake can you provide a screenshot? I can't understand how your Chrome can render that html incorrectly when both the browsers on my boot render it correctly. (edit: three browsers now, add Safari to IE and Chrome). – jthill Jul 02 '14 at 18:02
  • @jthill I wouldn't worry about it anymore. –  Jul 02 '14 at 18:25
  • @jthill, I'm a little late getting back to this. Yeah, the backslash crept in there in my question. I realise it's a shell continuation markup. Right, the manifest path makes sense. I'll try that again to check it out when I'm working on that part of the project again. –  Jul 13 '14 at 21:26