detect when there is nothing to stash - fix #9

This commit is contained in:
Josh Holtrop 2012-04-05 11:32:14 -04:00
parent 09a6f91f49
commit 50115bb998

14
jsvn
View File

@ -812,12 +812,22 @@ def stash(argv, svn, out):
stash_idx = get_next_stash_idx(svn) stash_idx = get_next_stash_idx(svn)
stash_fname = get_stash_fname(svn, stash_idx) stash_fname = get_stash_fname(svn, stash_idx)
fh = open(stash_fname, 'w') 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() fh.close()
if wrote_something:
Popen([svn, 'revert', '--depth=infinity', '.'], Popen([svn, 'revert', '--depth=infinity', '.'],
stdout=PIPE).wait() stdout=PIPE).wait()
os.chdir(owd)
out.write('Created stash %d\n' % stash_idx) out.write('Created stash %d\n' % stash_idx)
else:
out.write('Nothing to stash!\n')
os.unlink(stash_fname)
os.chdir(owd)
elif action == 'list': elif action == 'list':
stash_ids = get_stash_ids(svn) stash_ids = get_stash_ids(svn)
for si in reversed(stash_ids): for si in reversed(stash_ids):