2

Given that Git is very SHA-1 friendly, I would surmise that it is possible to easily check for this scenario:

-I have a repo with a directory foo/ somewhere within it. -Someone on some other computer makes a change to foo's contents (including nested subdirectories), and pushes the change to the repo.

My guess is that I will have to do a fetch and check if there is some difference between the SHA-1 for my directory and the SHA-1 of the remote directory, but I don't know how to do this.

Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
Ben
  • 7,692
  • 15
  • 49
  • 64

1 Answers1

6

you can simply use git diff --quiet and check its exit code:

git fetch # get latest code from upstream
git diff --quiet master..origin/master -- foo/ || echo 'directory differ'

diff --quiet will exit with 1 when there are differences and exit with an error code of 0 the objects (blob or tree) are identical

knittl
  • 246,190
  • 53
  • 318
  • 364