-for line in sys.stdin:
- (oldrev, newrev, refname) = line.split()
- if refname == "refs/heads/master":
- try:
- oldrev=file("refs/remotes/ftp/master").readline().strip();
- git_command = "/usr/bin/git diff --name-status %s %s"%(oldrev, newrev)
- except IOError:
- # We are run for the first time, so (A)dd all files in the repo.
- git_command = r"git ls-tree -r --name-only %s | sed -e 's/\(.*\)/A \1/'"%(newrev);
-
- add_to_change_list(changes, git_command)
-
+if 'GIT_DIR' in os.environ:
+ # Invocation from hook
+ for line in sys.stdin:
+ (oldrev, newrev, refname) = line.split()
+ if refname == "refs/heads/master":
+ try:
+ oldrev=file("refs/remotes/ftp/master").readline().strip();
+ git_command = "/usr/bin/git diff --name-status %s %s"%(oldrev, newrev)
+ except IOError:
+ # We are run for the first time, so (A)dd all files in the repo.
+ oldrev = None;
+ git_command = r"git ls-tree -r --name-only %s | sed -e 's/\(.*\)/A \1/'"%(newrev);
+
+ add_to_change_list(changes, git_command, oldrev, newrev)
+else:
+ # Manual invocation
+ newrev = "HEAD"
+ oldrev = None;
+ git_command = r"git ls-tree -r --name-only HEAD | sed -e 's/\(.*\)/A \1/'";
+ add_to_change_list(changes, git_command, oldrev, newrev)
+