Permalink
Browse files

Add Tox and now with Python 2.6 and 2.7 support

  • Loading branch information...
1 parent 37d2ad7 commit 5470c933d112167595fda90db01f5960725253d3 @robmadole robmadole committed Mar 21, 2012
View
@@ -12,3 +12,4 @@ dist
.jig
eggs
parts
+.tox
View
@@ -13,5 +13,6 @@ recipe = zc.recipe.egg:scripts
eggs = ${buildout:eggs}
nose
mock
+ tox
entry-points =
test=gitsweep.entrypoints:test
View
@@ -1,16 +1,19 @@
-from setuptools import setup, find_packages
+import sys
import os
+from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.rst')).read()
NEWS = open(os.path.join(here, 'NEWS.txt')).read()
-
version = '0.1.0'
install_requires = [
'GitPython>=0.3.2RC1']
+# Add argparse if less than Python 2.7
+if sys.version_info[0] <= 2 and sys.version_info[1] < 7:
+ install_requires.append('argparse>=1.2.1')
setup(name='git-sweep',
version=version,
View
@@ -50,7 +50,7 @@ def _master_ref(self, origin):
return ref
raise MissingMasterBranch(
- 'Could not find ref for {}'.format(self.master_branch))
+ 'Could not find ref for {0}'.format(self.master_branch))
@property
def _origin(self):
@@ -64,7 +64,7 @@ def _origin(self):
origin = remote
if not origin:
- raise MissingRemote('Could not find the remote named {}'.format(
+ raise MissingRemote('Could not find the remote named {0}'.format(
self.remote_name))
return origin
View
@@ -107,14 +107,14 @@ def _sweep(self):
if ok_to_delete:
sys.stdout.write(
- 'These branches have been merged into {}:\n\n'.format(
+ 'These branches have been merged into {0}:\n\n'.format(
master_branch))
else:
sys.stdout.write('No remote branches are available for '
'cleaning up\n')
for ref in ok_to_delete:
- sys.stdout.write(' {}\n'.format(ref.remote_head))
+ sys.stdout.write(' {0}\n'.format(ref.remote_head))
if not dry_run:
deleter = Deleter(repo, remote_name=remote_name,
@@ -125,16 +125,16 @@ def _sweep(self):
if answer.lower().startswith('y'):
sys.stdout.write('\n')
for ref in ok_to_delete:
- sys.stdout.write(' deleting {}'.format(ref.remote_head))
+ sys.stdout.write(' deleting {0}'.format(ref.remote_head))
deleter.remove_remote_refs([ref])
sys.stdout.write(' (done)\n')
sys.stdout.write('\nAll done!\n')
sys.stdout.write('\nTell everyone to run `git fetch --prune` '
'to sync with this remote.\n')
- sys.stdout.write('(you don\'t have to, your\'s is synced)')
+ sys.stdout.write('(you don\'t have to, your\'s is synced)\n')
else:
- sys.stdout.write('\nOK, aborting.')
+ sys.stdout.write('\nOK, aborting.\n')
elif ok_to_delete:
sys.stdout.write(
- '\nTo delete them, run again with `git-sweep cleanup`')
+ '\nTo delete them, run again with `git-sweep cleanup`\n')
View
@@ -17,6 +17,6 @@ def remove_remote_refs(self, refs):
pushes = []
for ref in refs:
- pushes.append(origin.push(':{}'.format(ref.remote_head)))
+ pushes.append(origin.push(':{0}'.format(ref.remote_head)))
return pushes
View
@@ -25,16 +25,17 @@ def merged_refs(self, skip=[]):
merged = []
for ref in refs:
- since_until = '{origin}/{master}..{origin}/{branch}'.format(
- origin=origin.name, master=master.remote_head,
- branch=ref.remote_head)
+ upstream = '{origin}/{master}'.format(
+ origin=origin.name, master=master.remote_head)
+ head = '{origin}/{branch}'.format(
+ origin=origin.name, branch=ref.remote_head)
cmd = Git(self.repo.working_dir)
# Drop to the git binary to do this, it's just easier to work with
# at this level.
- (retcode, _, _) = cmd.execute(
- ['git', 'log', '--exit-code', since_until],
+ (retcode, stdout, stderr) = cmd.execute(
+ ['git', 'cherry', upstream, head],
with_extended_output=True, with_exceptions=False)
- if retcode == 0:
+ if retcode == 0 and not stdout:
# This means there are no commits in the branch that are not
# also in the master branch. This is ready to be deleted.
merged.append(ref)
No changes.
@@ -0,0 +1,6 @@
+from gitsweep.entrypoints import test
+
+__test__ = False
+
+if __name__ == '__main__':
+ test()
@@ -59,11 +59,11 @@ def test_will_preview(self):
Will preview the proposed deletes.
"""
for i in range(1, 6):
- self.command('git checkout -b branch{}'.format(i))
+ self.command('git checkout -b branch{0}'.format(i))
self.make_commit()
self.command('git checkout master')
self.make_commit()
- self.command('git merge branch{}'.format(i))
+ self.command('git merge branch{0}'.format(i))
(retcode, stdout, stderr) = self.gscommand('git-sweep preview')
@@ -85,7 +85,7 @@ def test_will_preview_none_found(self):
Will preview the proposed deletes.
"""
for i in range(1, 6):
- self.command('git checkout -b branch{}'.format(i))
+ self.command('git checkout -b branch{0}'.format(i))
self.make_commit()
self.command('git checkout master')
@@ -101,11 +101,11 @@ def test_will_cleanup(self):
Will preview the proposed deletes.
"""
for i in range(1, 6):
- self.command('git checkout -b branch{}'.format(i))
+ self.command('git checkout -b branch{0}'.format(i))
self.make_commit()
self.command('git checkout master')
self.make_commit()
- self.command('git merge branch{}'.format(i))
+ self.command('git merge branch{0}'.format(i))
with patch('gitsweep.cli.raw_input', create=True) as ri:
ri.return_value = 'y'
@@ -139,11 +139,11 @@ def test_will_abort_cleanup(self):
Will preview the proposed deletes.
"""
for i in range(1, 6):
- self.command('git checkout -b branch{}'.format(i))
+ self.command('git checkout -b branch{0}'.format(i))
self.make_commit()
self.command('git checkout master')
self.make_commit()
- self.command('git merge branch{}'.format(i))
+ self.command('git merge branch{0}'.format(i))
with patch('gitsweep.cli.raw_input', create=True) as ri:
ri.return_value = 'n'
@@ -169,11 +169,11 @@ def test_will_skip_certain_branches(self):
Can be forced to skip certain branches.
"""
for i in range(1, 6):
- self.command('git checkout -b branch{}'.format(i))
+ self.command('git checkout -b branch{0}'.format(i))
self.make_commit()
self.command('git checkout master')
self.make_commit()
- self.command('git merge branch{}'.format(i))
+ self.command('git merge branch{0}'.format(i))
(retcode, stdout, stderr) = self.gscommand(
'git-sweep preview --skip=branch1,branch2')
@@ -12,11 +12,11 @@ def setUp(self):
super(TestDeleter, self).setUp()
for i in range(1, 6):
- self.command('git checkout -b branch{}'.format(i))
+ self.command('git checkout -b branch{0}'.format(i))
self.make_commit()
self.command('git checkout master')
self.make_commit()
- self.command('git merge branch{}'.format(i))
+ self.command('git merge branch{0}'.format(i))
def test_will_delete_merged_from_clone(self):
"""
@@ -18,7 +18,7 @@ def test_filtered_refs(self):
Will filter references and not return HEAD and master.
"""
for i in range(1, 4):
- self.command('git checkout -b branch{}'.format(i))
+ self.command('git checkout -b branch{0}'.format(i))
self.command('git checkout master')
refs = self.inspector._filtered_remotes(
@@ -114,11 +114,11 @@ def test_large_set_of_changes(self):
|/
"""
for i in range(1, 6):
- self.command('git checkout -b branch{}'.format(i))
+ self.command('git checkout -b branch{0}'.format(i))
self.make_commit()
self.command('git checkout master')
self.make_commit()
- self.command('git merge branch{}'.format(i))
+ self.command('git merge branch{0}'.format(i))
self.assertEqual(
['branch1', 'branch2', 'branch3', 'branch4', 'branch5'],
@@ -145,7 +145,7 @@ def make_commit(self):
fh.write(uuid().hex)
self.repo.index.add([basename(filename)])
- self.repo.index.commit('Adding {}'.format(basename(filename)))
+ self.repo.index.commit('Adding {0}'.format(basename(filename)))
class InspectorTestCase(TestCase):
View
11 tox.ini
@@ -0,0 +1,11 @@
+[testenv]
+deps =
+ nose
+ mock
+commands = python -m gitsweep.scripts.test
+
+[testenv:2.6]
+basepython = python2.6
+
+[testenv:2.7]
+basepython = python2.7

0 comments on commit 5470c93

Please sign in to comment.