From ec689d00ba28758c5c5c4fbb1b4ee5242636372d Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Tue, 23 Sep 2008 13:58:00 +0000 Subject: [PATCH] First run uploads the whole current tree, not only the changes in the last commit darcs-hash:20080923135839-f2ef6-0f0cfb2677ff6734c9fd719317e4cd52151734f6.gz --- git-ftp-sync | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/git-ftp-sync b/git-ftp-sync index cd570ff..73fd7ab 100755 --- a/git-ftp-sync +++ b/git-ftp-sync @@ -180,18 +180,30 @@ def selftest(): mkdir repo.git cd repo.git git --bare init - echo -e "%s" > hooks/pre-receive - chmod +x hooks/pre-receive REPO=$PWD cd .. mkdir www mkdir working cd working git init + mkdir www + + # Commit something to www directory in repo without the activated hook + echo 'Bye' > www/first.html + git add www/first.html + commit_push 'Added first.html' + + # Activate the hook and commit a non-mirrored file + echo "%s" > $REPO/hooks/post-receive + chmod +x $REPO/hooks/post-receive echo 'abc' > non-mirrored-file git add non-mirrored-file commit_push 'Added non-mirrored-file' - mkdir www + + # 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 + cd www echo 'Hello' > index.html git add index.html @@ -214,6 +226,8 @@ def selftest(): cd .. git rm www/index2.html commit_push 'Removed index2' + git rm www/first.html + commit_push 'Removed first.html' cd $REPO/.. rm -rf working repo.git www """ @@ -244,9 +258,9 @@ def update_ref(hash): os.makedirs("refs/remotes/"+remote) file("refs/remotes/"+remote+"/"+branch, "w").write(newrev+"\n") -def build_change_list(changes, oldrev, newrev): +def add_to_change_list(changes, git_command): # Read changes - gitdiff = Popen("/usr/bin/git diff --name-status %s %s"%(oldrev, newrev), + gitdiff = Popen(git_command, stdout=PIPE, stderr=PIPE, close_fds=True, shell=True) change_re = re.compile("(\S+)\s+(.*)$"); for line in gitdiff.stdout: @@ -257,8 +271,6 @@ def build_change_list(changes, oldrev, newrev): if change.inDir(options.repodir): changes.append(change) - - # Parse command line options (options, args) = opt_parser.parse_args() @@ -277,9 +289,12 @@ for line in sys.stdin: 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: - pass - build_change_list(changes, oldrev, newrev) + # 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 not changes: perror("No changes to sync") -- 2.39.2