1

Yesterday I was trying to help a co-worker with some Git stuff and told him to do a git reset --hard when I thought he was on his local repo but he was on our live server. This messed a bunch of things up, I think mainly because on our live server we have tons of local uncommitted files on the server, which were uploaded directly through Drupal rather than through committing then pushing/pulling in Git.

I'd like to prevent this from happening again. Is there a git hook that I could write that could prevent anyone from ever doing a git reset --hard on the live server?

Jan
  • 848
  • 7
  • 17
  • Not a direct awnser to the question but what about a whitelist-gitignore? So that everything, that is not under version control ('direct uploads') is not marked as `untracked`. See this post for an example: http://stackoverflow.com/questions/15288712/gitignore-whitelist-on-directory-and-its-contents – Jo Oko Jul 01 '15 at 17:30
  • @JoOko, I believe that would be difficult because we also have some specific edits on the server (`.htaccess` files are different that on our local copies, for example) in random places ... Another problem is that after the `git reset --hard`, a bunch of files had disappeared and we found that Drupal had moved them to locations other than the ones we uploaded them originally. So it's not just one folder, unfortunately ... Although I will run that idea by my boss and see what he thinks of it. – Jan Jul 01 '15 at 17:41

1 Answers1

5

Having lots of uncommitted files on the server makes it sound like you're not using it as a server, but a a shared git workspace. That is the problem. If you were hosting the git repository on the server 'properly' then it would be a bare repo (i.e. without a checkout) and users would simply pull/push to that.

You can get the effect of a checked out directory by having a git hook (something like post-receive would work) that performs a checkout to another area. But you should treat that area as being a read-only copy, not a writable work-in-progress.

AlBlue
  • 23,254
  • 14
  • 71
  • 91
  • The server I'm talking about is not our Git server, it's our web server. The central git repo is on an entirely different server. – Jan Jul 03 '15 at 17:47