Skip to content

Commit

Permalink
(arc90#38): Don't prompt for deletion if there aren't any branches to…
Browse files Browse the repository at this point in the history
… delete.
  • Loading branch information
jwir3 committed Jun 20, 2015
1 parent 83be28e commit 7832375
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
33 changes: 17 additions & 16 deletions src/gitsweep/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,23 @@ def _sweep(self):
deleter = Deleter(repo, remote_name=remote_name,
master_branch=master_branch)

if not args.force:
sys.stdout.write('\nDelete these branches? (y/n) ')
answer = raw_input()
if args.force or answer.lower().startswith('y'):
sys.stdout.write('\n')
for ref in ok_to_delete:
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, yours is synced)\n')
else:
sys.stdout.write('\nOK, aborting.\n')
if ok_to_delete:
if not args.force:
sys.stdout.write('\nDelete these branches? (y/n) ')
answer = raw_input()
if args.force or answer.lower().startswith('y'):
sys.stdout.write('\n')
for ref in ok_to_delete:
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, yours is synced)\n')
else:
sys.stdout.write('\nOK, aborting.\n')
elif ok_to_delete:
# Replace the first argument with cleanup
sysv_copy = self.args[:]
Expand Down
16 changes: 14 additions & 2 deletions src/gitsweep/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_will_preview_none_found(self):

def test_will_cleanup(self):
"""
Will preview the proposed deletes.
Will cleanup the proposed deletes.
"""
for i in range(1, 6):
self.command('git checkout -b branch{0}'.format(i))
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_will_cleanup(self):

def test_will_abort_cleanup(self):
"""
Will preview the proposed deletes.
Will abort cleanup on user request
"""
for i in range(1, 6):
self.command('git checkout -b branch{0}'.format(i))
Expand Down Expand Up @@ -252,3 +252,15 @@ def test_will_force_clean(self):
Tell everyone to run `git fetch --prune` to sync with this remote.
(you don't have to, yours is synced)
''', stdout)

def test_cleanup_no_branches_found(self):
"""
Will not prompt user if no branches are found that can be cleaned up
"""
(retcode, stdout, stderr) = self.gscommand('git-sweep cleanup --force')

self.assertResults('''
Fetching from the remote
No remote branches are available for cleaning up
''', stdout)

0 comments on commit 7832375

Please sign in to comment.