~abentley/bzrtools/bzrtools.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python

# Copyright (C) 2005 by Aaron Bentley

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
import bzrlib
from bzrlib import Branch
from bzrlib.diff import diff_trees
import sys
import os
import scriptlib
bzrlib.trace.create_tracefile([])

cur_branch = Branch(".")
pull_location, pull_revision = scriptlib.get_pull_data(cur_branch)
if pull_location is not None:
    if cur_branch.last_patch() != pull_revision:
        print "Aborting: This branch has had commits, so pull would lose data."
        sys.exit(1)
if len(sys.argv) > 1:
    pull_location = sys.argv[1] 
    if not pull_location.endswith('/'):
        pull_location.append('/')

if pull_location is None:
    print "No pull location saved.  Please specify one on the command line."
    sys.exit(1)

if not scriptlib.is_clean(cur_branch):
    print "Error: This tree has uncommitted changes or unknown (?) files."
    sys.exit(1)

print "Synchronizing with %s" % pull_location
args = " ".join(("rsync", "-av", "--delete", pull_location, cur_branch.base))
os.system(args)

scriptlib.set_pull_data(cur_branch, pull_location, cur_branch.last_patch())