From 50115bb99865e04bec0c67bf0b10481a4d187e81 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 5 Apr 2012 11:32:14 -0400 Subject: [PATCH] detect when there is nothing to stash - fix #9 --- jsvn | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/jsvn b/jsvn index 5806f69..67bc372 100755 --- a/jsvn +++ b/jsvn @@ -812,12 +812,22 @@ def stash(argv, svn, out): stash_idx = get_next_stash_idx(svn) stash_fname = get_stash_fname(svn, stash_idx) fh = open(stash_fname, 'w') - Popen([svn, 'diff'], stdout=fh).wait() + proc = Popen([svn, 'diff'], stdout=PIPE) + wrote_something = False + for line in iter(proc.stdout.readline, ''): + if len(line) > 0: + wrote_something = True + fh.write(line) + proc.wait() fh.close() - Popen([svn, 'revert', '--depth=infinity', '.'], - stdout=PIPE).wait() + if wrote_something: + Popen([svn, 'revert', '--depth=infinity', '.'], + stdout=PIPE).wait() + out.write('Created stash %d\n' % stash_idx) + else: + out.write('Nothing to stash!\n') + os.unlink(stash_fname) os.chdir(owd) - out.write('Created stash %d\n' % stash_idx) elif action == 'list': stash_ids = get_stash_ids(svn) for si in reversed(stash_ids):