1

I have a small Bash script which includes some Git commands. (For certain reasons, I cannot use git hooks here.)

Basically, it does

git pull origin <<some repo>> || { echo "Git pull FAILED"; exit 1; }
# do something with the new/changed files on the file system

In not reproducible cases, this fails. In these cases, old versions of the files (being at the state before git pull) are used instead of the new files (at the state after git pull). However, if I manually do git pull and afterward run the other command, there was never any problem.

So, I'm now wondering if there is any delay/asynchronicity in Git changing the files on the file system after a pull. If yes: How can I deal with it (maybe avoiding sleep or something like that)? If not: What else could cause the confusion of file versions here?

cis
  • 1,259
  • 15
  • 48
  • Git operations are supposed to be atomic. If so, this would imply that Git locks down the entire repo folder during a pull and only releases the lock if the entire pull were successful. I can't find any literature to support this guess though. – Tim Biegeleisen Feb 22 '18 at 11:08
  • Are you sure the `pull` command don't fail? That could explain why you still are in older version of the repo. – Arount Feb 22 '18 at 11:10
  • 2
    @TimBiegeleisen the lock you mentioned protects the repo against concurrent Git operations. It doesn't prevent other programs reading or writing the files while Git is working. – axiac Feb 22 '18 at 11:20
  • @axiac Good to know. Then there might not be a clean solution here. – Tim Biegeleisen Feb 22 '18 at 11:21
  • This exact thing happened to me before. Here, refer this: https://stackoverflow.com/questions/48839604/git-pull-and-then-push-via-cron-in-ubuntu – naqushab Feb 22 '18 at 11:34
  • @Arount Yes, I'm sure that Git pull doesn't fail, since I handle that case. I've edit my code snippet showing that part. – cis Feb 22 '18 at 12:41
  • You are not showing enough code for me to tell what's going wrong, but I will say: avoid `git pull`. *Especially* avoid it in any script. Break it into its two components, `git fetch` followed by (if fetch succeeds) `git merge`. – torek Feb 22 '18 at 14:24

0 Answers0