self.mkd(change.dest_path)
elif change.type[0] in ["A", "C", "M"]:
# Check whether the target directory exists
- retcode = call("git ls-tree %s %s|grep -q ." % (change.oldrev, dirname(change.repo_path)), shell=True)
- if (retcode != 0 and normpath(dirname(change.dest_path)) != normpath(dest_root)):
- self.mkd(dirname(change.dest_path))
+ if (normpath(dirname(change.dest_path)) != normpath(dest_root)):
+ retcode = 1
+ if (change.oldrev): # If there is previous revision, check for it
+ retcode = call("git ls-tree %s %s|grep -q ." % (change.oldrev, dirname(change.repo_path)), shell=True)
+ if (retcode != 0):
+ dirs = normpath(dirname(change.dest_path)).split("/")
+ #print "YYYYYYYYYYYYY",dirname(change.dest_path)
+ destdir = ""
+ for i in dirs:
+ if (i==""): i="/"
+ destdir = os.path.join(destdir, i);
+ #print "XXXXXXXXXXXXX",destdir
+ #self.mkd(dirname(change.dest_path))
+ self.mkd(destdir)
+
# Upload the file
print "%s: UPLOAD"%self.__class__.__name__, change.dest_path
pipe = Popen("git cat-file blob %s:%s" % (change.newrev, change.repo_path),
mkdir www
# Commit something to www directory in repo without the activated hook
- echo 'Bye' > www/first.html
- git add www/first.html
+ mkdir www/dir
+ mkdir www/dir/dir2
+ echo 'Bye' > www/dir/dir2/first.html
+ git add www/dir/dir2/first.html
commit_push 'Added first.html'
# Activate the hook and commit a non-mirrored file
# Check that the first commit appears in www even if the hook was
# activated later (only for local sync)
- grep -q PASSWORD $REPO/hooks/post-receive || test -f ../www/first.html
+ grep -q PASSWORD $REPO/hooks/post-receive || test -f ../www/dir/dir2/first.html
cd www
echo 'Hello' > index.html
cd ..
git rm www/index2.html
commit_push 'Removed index2'
- git rm www/first.html
+ git rm www/dir/dir2/first.html
commit_push 'Removed first.html'
cd $REPO/..
rm -rf working repo.git www
os.makedirs("refs/remotes/"+remote)
file("refs/remotes/"+remote+"/"+branch, "w").write(newrev+"\n")
-def add_to_change_list(changes, git_command):
+def add_to_change_list(changes, git_command, oldrev, newrev):
# Read changes
gitdiff = Popen(git_command,
stdout=PIPE, stderr=PIPE, close_fds=True, shell=True)
changes = list()
# Read the changes
-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)
+
if not changes:
perror("No changes to sync")
sys.exit(0)