1

What I'm trying to achieve

I have a Git repository on the host system, which is shared with a docker container. Inside the docker container, I would like to get the files that have been changed/staged. I also want to be able to add files to be staged in the host system.

Essentially, a pre-commit hook on the host is going to call a program inside the docker image, which will then check/change files that are going to be committed.

What I've tried

From this question: git forces refresh index after switching between windows and linux

I've tried adding the GIT_INDEX_FILE argument, but at best, it results in separate staging areas, so the docker image doesn't end up working with the host's staging areas.

Without that argument, I need to run git status in the container each time, which then refreshes the index every time.

Notes

This will likely only be running on a Mac OS X host system, and Linux docker container.

Sam Bull
  • 2,559
  • 1
  • 15
  • 17
  • As you can see in the linked question it's not recommended. Also see https://stackoverflow.com/q/47011576/7976758 – phd Jun 02 '20 at 18:08
  • use SSH to remote access the repo? doesnt controlling the host system from outside a container contradict what a container does? – TheDudeWithHat Jun 02 '20 at 18:41

1 Answers1

3

As mentioned in the question you linked, this isn't recommended. Git stores a lot of metadata about the files in the index, including things like the device and inode number. Those items are necessarily going to differ between macOS and the Linux kernel that runs the container.

Git is not designed around sharing working trees between systems because its security model treats anything that isn't a fetch or clone from an untrusted repository as unsafe. It's therefore not intended to share non-bare repositories, even across operating systems on the same computer.

You can try setting core.checkStat to minimal and, if that isn't sufficient, core.trustctime to false. If those don't work, then you'll probably need to do a git update-index --refresh in your hook, which is the plumbing (scripting) command for updating the index. That wouldn't be avoidable if those config options don't work for you.

Note that setting these options means that you run the risk of Git not detecting changes, so they are not magical solutions, but instead a workaround.

KindDragon
  • 6,558
  • 4
  • 47
  • 75
bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Hmm, I think I'm probably going to have to figure out a way of running all the Git commands on the host system, and piping the information in and out of the docker container. – Sam Bull Jun 03 '20 at 16:59