Skip to content

Commit

Permalink
Merge branch 'master' of github.com:peritus/geocommit
Browse files Browse the repository at this point in the history
  • Loading branch information
dsp committed Apr 14, 2011
2 parents 08e9f68 + 2e29db4 commit 00fed9f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
47 changes: 18 additions & 29 deletions src/geocommit/__init__.py
Expand Up @@ -108,31 +108,9 @@ def fetch_and_merge_notes(self, remote):
remote_changes = system("git rev-list --max-count=1 refs/notes/geocommit..FETCH_HEAD").strip('\n\r ')

if remote_changes:

stash = "\"geocommit temporary stash\""
code, output = system_exit_code("git stash save " + stash)

if code != 0:
print output

else:
current_rev = system("git symbolic-ref -q HEAD").strip('\n\r ')

if not current_rev:
current_rev = system("git rev-parse HEAD").strip('\n\r ')
elif current_rev.find("refs/heads/") == 0:
current_rev = current_rev[len("refs/heads/"):]

system_exit_code("git checkout refs/notes/geocommit")
print "Merging geocommit notes"
system_exit_code("git merge --strategy=recursive -Xtheirs -Xrename-threshold=100% FETCH_HEAD")
rev = system("git rev-parse HEAD").strip('\n\r ')
system_exit_code("git update-ref refs/notes/geocommit " + rev)

print "Restoring working diretory"
system_exit_code("git checkout " + current_rev)
system_exit_code("git stash apply")
system_exit_code("git stash drop " + stash)
print "Merging geocommit notes"
system_exit_code("git update-ref refs/notes/geocommit-remote FETCH_HEAD")
system_exit_code("git notes --ref geocommit merge --strategy=theirs geocommit-remote")
else:
print "Already up-to-date."

Expand Down Expand Up @@ -162,7 +140,10 @@ def get_remote(self):
return None

def cmd_note(self, argv):
print "Retrieving location ...",
sys.stdout.flush()
note = self.get_note()
print "found."

git_rev = self.git_rev

Expand Down Expand Up @@ -216,7 +197,7 @@ def cmd_pull(self, argv):

self.fetch_and_merge_notes(argv[0])

def cmd_sync(self, argv):
def cmd_sync(self, argv, push=True):
if len(argv) == 0:
remote = self.get_remote()
if remote:
Expand All @@ -229,8 +210,9 @@ def cmd_sync(self, argv):

self.fetch_and_merge_notes(argv[0])

print "Syncing geocommit notes"
forward_system("git push " + argv[0] + " refs/notes/geocommit")
if push:
print "Syncing geocommit notes"
forward_system("git push " + argv[0] + " refs/notes/geocommit")

def cmd_push(self, argv):
opt_definition = {
Expand All @@ -247,6 +229,7 @@ def cmd_push(self, argv):
"-f": "bool",
"--force": "bool",
"--thin": "bool",
"--no-thin": "bool",
"--receive-pack": "string",
"--exec": "string",
"-u": "bool",
Expand All @@ -260,11 +243,17 @@ def cmd_push(self, argv):
remote = self.get_remote()
if remote:
arguments = [remote]
argv += [remote]
else:
print >> sys.stderr, "Cannot push geo data: No remote specified"
usage("push")
if len(arguments) == 1:
arguments += [":"]
argv += [":"]

argv += ["refs/notes/geocommit"]

self.cmd_sync([arguments[0]])
self.cmd_sync([arguments[0]], False)

forward_system(["git", "push"] + argv)

Expand Down
25 changes: 25 additions & 0 deletions tests/geogit.sh
@@ -0,0 +1,25 @@
rm -rf foo
rm -rf bar

mkdir foo
cd foo
git init
git geo setup
touch file1
git add file1
git commit -m "Add file1"
git checkout -b not-master
cd ../

git clone foo bar
cd bar
git geo setup
echo "content" > file1
git commit -a -m "Write content to file1"
git geo push origin master:master
cd ..

cd foo
git remote add bar ../bar
git checkout master
git log --show-notes=geocommit

0 comments on commit 00fed9f

Please sign in to comment.