Skip to content

Commit 5470c93

Browse files
committed
Add Tox and now with Python 2.6 and 2.7 support
1 parent 37d2ad7 commit 5470c93

14 files changed

+55
-32
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ dist
1212
.jig
1313
eggs
1414
parts
15+
.tox

buildout.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ recipe = zc.recipe.egg:scripts
1313
eggs = ${buildout:eggs}
1414
nose
1515
mock
16+
tox
1617
entry-points =
1718
test=gitsweep.entrypoints:test

setup.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
from setuptools import setup, find_packages
1+
import sys
22
import os
3+
from setuptools import setup, find_packages
34

45
here = os.path.abspath(os.path.dirname(__file__))
56
README = open(os.path.join(here, 'README.rst')).read()
67
NEWS = open(os.path.join(here, 'NEWS.txt')).read()
78

8-
99
version = '0.1.0'
1010

1111
install_requires = [
1212
'GitPython>=0.3.2RC1']
1313

14+
# Add argparse if less than Python 2.7
15+
if sys.version_info[0] <= 2 and sys.version_info[1] < 7:
16+
install_requires.append('argparse>=1.2.1')
1417

1518
setup(name='git-sweep',
1619
version=version,

src/gitsweep/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _master_ref(self, origin):
5050
return ref
5151

5252
raise MissingMasterBranch(
53-
'Could not find ref for {}'.format(self.master_branch))
53+
'Could not find ref for {0}'.format(self.master_branch))
5454

5555
@property
5656
def _origin(self):
@@ -64,7 +64,7 @@ def _origin(self):
6464
origin = remote
6565

6666
if not origin:
67-
raise MissingRemote('Could not find the remote named {}'.format(
67+
raise MissingRemote('Could not find the remote named {0}'.format(
6868
self.remote_name))
6969

7070
return origin

src/gitsweep/cli.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ def _sweep(self):
107107

108108
if ok_to_delete:
109109
sys.stdout.write(
110-
'These branches have been merged into {}:\n\n'.format(
110+
'These branches have been merged into {0}:\n\n'.format(
111111
master_branch))
112112
else:
113113
sys.stdout.write('No remote branches are available for '
114114
'cleaning up\n')
115115

116116
for ref in ok_to_delete:
117-
sys.stdout.write(' {}\n'.format(ref.remote_head))
117+
sys.stdout.write(' {0}\n'.format(ref.remote_head))
118118

119119
if not dry_run:
120120
deleter = Deleter(repo, remote_name=remote_name,
@@ -125,16 +125,16 @@ def _sweep(self):
125125
if answer.lower().startswith('y'):
126126
sys.stdout.write('\n')
127127
for ref in ok_to_delete:
128-
sys.stdout.write(' deleting {}'.format(ref.remote_head))
128+
sys.stdout.write(' deleting {0}'.format(ref.remote_head))
129129
deleter.remove_remote_refs([ref])
130130
sys.stdout.write(' (done)\n')
131131

132132
sys.stdout.write('\nAll done!\n')
133133
sys.stdout.write('\nTell everyone to run `git fetch --prune` '
134134
'to sync with this remote.\n')
135-
sys.stdout.write('(you don\'t have to, your\'s is synced)')
135+
sys.stdout.write('(you don\'t have to, your\'s is synced)\n')
136136
else:
137-
sys.stdout.write('\nOK, aborting.')
137+
sys.stdout.write('\nOK, aborting.\n')
138138
elif ok_to_delete:
139139
sys.stdout.write(
140-
'\nTo delete them, run again with `git-sweep cleanup`')
140+
'\nTo delete them, run again with `git-sweep cleanup`\n')

src/gitsweep/deleter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ def remove_remote_refs(self, refs):
1717

1818
pushes = []
1919
for ref in refs:
20-
pushes.append(origin.push(':{}'.format(ref.remote_head)))
20+
pushes.append(origin.push(':{0}'.format(ref.remote_head)))
2121

2222
return pushes

src/gitsweep/inspector.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ def merged_refs(self, skip=[]):
2525
merged = []
2626

2727
for ref in refs:
28-
since_until = '{origin}/{master}..{origin}/{branch}'.format(
29-
origin=origin.name, master=master.remote_head,
30-
branch=ref.remote_head)
28+
upstream = '{origin}/{master}'.format(
29+
origin=origin.name, master=master.remote_head)
30+
head = '{origin}/{branch}'.format(
31+
origin=origin.name, branch=ref.remote_head)
3132
cmd = Git(self.repo.working_dir)
3233
# Drop to the git binary to do this, it's just easier to work with
3334
# at this level.
34-
(retcode, _, _) = cmd.execute(
35-
['git', 'log', '--exit-code', since_until],
35+
(retcode, stdout, stderr) = cmd.execute(
36+
['git', 'cherry', upstream, head],
3637
with_extended_output=True, with_exceptions=False)
37-
if retcode == 0:
38+
if retcode == 0 and not stdout:
3839
# This means there are no commits in the branch that are not
3940
# also in the master branch. This is ready to be deleted.
4041
merged.append(ref)

src/gitsweep/scripts/__init__.py

Whitespace-only changes.

src/gitsweep/scripts/test.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from gitsweep.entrypoints import test
2+
3+
__test__ = False
4+
5+
if __name__ == '__main__':
6+
test()

src/gitsweep/tests/test_cli.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ def test_will_preview(self):
5959
Will preview the proposed deletes.
6060
"""
6161
for i in range(1, 6):
62-
self.command('git checkout -b branch{}'.format(i))
62+
self.command('git checkout -b branch{0}'.format(i))
6363
self.make_commit()
6464
self.command('git checkout master')
6565
self.make_commit()
66-
self.command('git merge branch{}'.format(i))
66+
self.command('git merge branch{0}'.format(i))
6767

6868
(retcode, stdout, stderr) = self.gscommand('git-sweep preview')
6969

@@ -85,7 +85,7 @@ def test_will_preview_none_found(self):
8585
Will preview the proposed deletes.
8686
"""
8787
for i in range(1, 6):
88-
self.command('git checkout -b branch{}'.format(i))
88+
self.command('git checkout -b branch{0}'.format(i))
8989
self.make_commit()
9090
self.command('git checkout master')
9191

@@ -101,11 +101,11 @@ def test_will_cleanup(self):
101101
Will preview the proposed deletes.
102102
"""
103103
for i in range(1, 6):
104-
self.command('git checkout -b branch{}'.format(i))
104+
self.command('git checkout -b branch{0}'.format(i))
105105
self.make_commit()
106106
self.command('git checkout master')
107107
self.make_commit()
108-
self.command('git merge branch{}'.format(i))
108+
self.command('git merge branch{0}'.format(i))
109109

110110
with patch('gitsweep.cli.raw_input', create=True) as ri:
111111
ri.return_value = 'y'
@@ -139,11 +139,11 @@ def test_will_abort_cleanup(self):
139139
Will preview the proposed deletes.
140140
"""
141141
for i in range(1, 6):
142-
self.command('git checkout -b branch{}'.format(i))
142+
self.command('git checkout -b branch{0}'.format(i))
143143
self.make_commit()
144144
self.command('git checkout master')
145145
self.make_commit()
146-
self.command('git merge branch{}'.format(i))
146+
self.command('git merge branch{0}'.format(i))
147147

148148
with patch('gitsweep.cli.raw_input', create=True) as ri:
149149
ri.return_value = 'n'
@@ -169,11 +169,11 @@ def test_will_skip_certain_branches(self):
169169
Can be forced to skip certain branches.
170170
"""
171171
for i in range(1, 6):
172-
self.command('git checkout -b branch{}'.format(i))
172+
self.command('git checkout -b branch{0}'.format(i))
173173
self.make_commit()
174174
self.command('git checkout master')
175175
self.make_commit()
176-
self.command('git merge branch{}'.format(i))
176+
self.command('git merge branch{0}'.format(i))
177177

178178
(retcode, stdout, stderr) = self.gscommand(
179179
'git-sweep preview --skip=branch1,branch2')

src/gitsweep/tests/test_deleter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def setUp(self):
1212
super(TestDeleter, self).setUp()
1313

1414
for i in range(1, 6):
15-
self.command('git checkout -b branch{}'.format(i))
15+
self.command('git checkout -b branch{0}'.format(i))
1616
self.make_commit()
1717
self.command('git checkout master')
1818
self.make_commit()
19-
self.command('git merge branch{}'.format(i))
19+
self.command('git merge branch{0}'.format(i))
2020

2121
def test_will_delete_merged_from_clone(self):
2222
"""

src/gitsweep/tests/test_inspector.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_filtered_refs(self):
1818
Will filter references and not return HEAD and master.
1919
"""
2020
for i in range(1, 4):
21-
self.command('git checkout -b branch{}'.format(i))
21+
self.command('git checkout -b branch{0}'.format(i))
2222
self.command('git checkout master')
2323

2424
refs = self.inspector._filtered_remotes(
@@ -114,11 +114,11 @@ def test_large_set_of_changes(self):
114114
|/
115115
"""
116116
for i in range(1, 6):
117-
self.command('git checkout -b branch{}'.format(i))
117+
self.command('git checkout -b branch{0}'.format(i))
118118
self.make_commit()
119119
self.command('git checkout master')
120120
self.make_commit()
121-
self.command('git merge branch{}'.format(i))
121+
self.command('git merge branch{0}'.format(i))
122122

123123
self.assertEqual(
124124
['branch1', 'branch2', 'branch3', 'branch4', 'branch5'],

src/gitsweep/tests/testcases.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def make_commit(self):
145145
fh.write(uuid().hex)
146146

147147
self.repo.index.add([basename(filename)])
148-
self.repo.index.commit('Adding {}'.format(basename(filename)))
148+
self.repo.index.commit('Adding {0}'.format(basename(filename)))
149149

150150

151151
class InspectorTestCase(TestCase):

tox.ini

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[testenv]
2+
deps =
3+
nose
4+
mock
5+
commands = python -m gitsweep.scripts.test
6+
7+
[testenv:2.6]
8+
basepython = python2.6
9+
10+
[testenv:2.7]
11+
basepython = python2.7

0 commit comments

Comments
 (0)