Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#38): Don't prompt for deletion if there aren't any branches to delete. #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)