Skip to content

Commit

Permalink
Renamed cu to in. Fixed implementations and updated readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
chintal committed Sep 9, 2015
1 parent 7826455 commit ee76ef0
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 34 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ co
missing
Print directories that are missing from the config file

out
Show changesets you haven't pushed to the server yet

in
Show incoming changesets that would be pulled in with 'up'. For some
version control systems, this depends on the English output of the
respective commands and is therefore inherently fragile.



Hidden commands
---------------
Expand Down
106 changes: 75 additions & 31 deletions checkoutmanager/dirinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def cmd_exists(self, report_only_missing=False):
def cmd_rev(self):
raise NotImplementedError()

def cmd_cu(self):
def cmd_in(self):
raise NotImplementedError()

def cmd_up(self):
Expand Down Expand Up @@ -80,24 +80,35 @@ class SvnDirInfo(DirInfo):

vcs = 'svn'

rex_last_changed = re.compile('Last Changed Rev: (?P<rev>\d+)')

def _parse_last_changed(self, output):
lines = [line.strip() for line in output.splitlines()
if line.strip()]
for line in lines:
m = self.rex_last_changed.match(line)
if m:
return m.group('rev')

@capture_stdout
def cmd_rev(self):
print(self.directory)
os.chdir(self.directory)
print(system("svn info | grep -i \"Last Changed Rev\""))
output = system("svn info")
print(self._parse_last_changed(output))

@capture_stdout
def cmd_cu(self):
def cmd_in(self):
os.chdir(self.directory)
output = system("svn info | grep -i \"Last Changed Rev\"")
local_rev = int(re.findall('\d+', output)[0])
output = system("svn info")
local_rev = self._parse_last_changed(output)
try:
output = system("svn info -r HEAD| grep -i \"Last Changed Rev\"")
remote_rev = int(re.findall('\d+', output)[0])
output = system("svn info -r HEAD")
remote_rev = self._parse_last_changed(output)
if remote_rev > local_rev:
print(self.directory)
print("Incoming changes : "
"Rev {0} to {1}".format(local_rev, remote_rev))
"Revision {0} to {1}".format(local_rev, remote_rev))
except CommandError:
print("Could not connect to repository for " + self.directory)
return
Expand Down Expand Up @@ -188,19 +199,26 @@ class BzrDirInfo(DirInfo):
def cmd_rev(self):
print(self.directory)
os.chdir(self.directory)
print(system("bzr log -r-1"))
print(system("bzr revno"))

@capture_stdout
def cmd_cu(self):
output = system("bzr missing")
output = output.strip()
output_lines = output.split('\n')
if "Branches are up to date." in output_lines:
return
if len(output_lines):
print("'bzr missing' reports possible actions in %s:" % (
self.directory))
print(output)
def cmd_in(self):
os.chdir(self.directory)
try:
system("bzr missing --theirs-only")
except CommandError as e:
if e.returncode == 1:
# bzr returns 1 if there are incoming changes!
print(self.directory)
print("'bzr missing' reports incoming changsets : ")
print(e.output)
return
if e.returncode == 3:
# bzr returns 3 if there is no parent
pass
else:
raise
return

@capture_stdout
def cmd_up(self):
Expand Down Expand Up @@ -252,23 +270,40 @@ class HgDirInfo(DirInfo):

vcs = 'hg'

rex_changeset = re.compile('changeset:\s+((?P<num>\d+):(?P<digest>[0-9a-fA-F]+))')

@capture_stdout
def cmd_rev(self):
print(self.directory)
os.chdir(self.directory)
print(system("hg log -l1"))
output = system("hg log -l1")
lines = [line.strip() for line in output.splitlines()
if line.strip()]
for line in lines:
m = self.rex_changeset.match(line)
if m:
print("{0}:{1}".format(m.group('num'), m.group('digest')))
return

@capture_stdout
def cmd_cu(self):
output = system("hg incoming")
output = output.strip()
output_lines = output.split('\n')
if "no changes found" in output_lines:
return
if len(output_lines):
print("'hg incoming' reports possible actions in %s:" % (
self.directory))
def cmd_in(self):
os.chdir(self.directory)
try:
output = system("hg incoming")
print(self.directory)
print("'hg incoming' reports incoming changesets :" % (
self.directory))
print(output)
except CommandError as e:
if e.returncode == 1:
# hg returns 1 if there are no incoming changes.
return
elif e.returncode == 255:
# hg returns 255 if there is no default parent.
pass
else:
raise
return

@capture_stdout
def cmd_up(self):
Expand Down Expand Up @@ -323,14 +358,23 @@ class GitDirInfo(DirInfo):

vcs = 'git'

rex_commit_digest = re.compile('commit (?P<digest>[0-9a-fA-F]+)')

@capture_stdout
def cmd_rev(self):
print(self.directory)
os.chdir(self.directory)
print(system("git show -q"))
output = system("git show -q")
lines = [line.strip() for line in output.splitlines()
if line.strip()]
for line in lines:
m = self.rex_commit_digest.match(line)
if m:
print(m.group('object'))
return

@capture_stdout
def cmd_cu(self):
def cmd_in(self):
output = system("git pull --dry-run")
output = output.strip()
output_lines = output.split('\n')
Expand Down
6 changes: 3 additions & 3 deletions checkoutmanager/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from checkoutmanager.executors import get_executor


ACTIONS = ['exists', 'up', 'st', 'co', 'missing', 'out', 'cu', 'rev']
ACTIONS = ['exists', 'up', 'st', 'co', 'missing', 'out', 'in', 'rev']
CONFIGFILE_NAME = '~/.checkoutmanager.cfg'
ACTION_EXPLANATION = {
'exists': "Print whether checkouts are present or missing",
Expand All @@ -22,8 +22,8 @@
'co': "Grab missing checkouts from the server",
'missing': "Print directories that are missing from the config file",
'out': "Show changesets you haven't pushed to the server yet",
'cu': "Check for updates that will be pulled in with 'up'",
'rev': "Get the current revision information",
'in': "Show incoming changesets that would be pulled in with 'up'",
'rev': "Print the current revision number",
}


Expand Down

0 comments on commit ee76ef0

Please sign in to comment.