Permalink
Browse files

gitcommit: better status check and report

  • Loading branch information...
1 parent a56ce02 commit 0936367420a17b97b02b136976d225b662dff460 @dr4Ke committed Jan 21, 2013
Showing with 17 additions and 9 deletions.
  1. +17 −9 0.11/tracgitosis/tracgitosis.py
@@ -375,28 +375,36 @@ def gitcommit(repodir, file, tracinstancename='', action='add'):
stderr = ''
message = ''
status = 0
- # commiting
+ # add/remove file
cmd = ['git', action, file]
proc = Popen(cmd, shell=False, stdin=None, stdout=PIPE, stderr=PIPE, cwd=repodir)
stdout, stderr = proc.communicate()
status = proc.returncode
- cmd = ['git', 'commit', '-m', 'commited by trac instance: ' + tracinstancename ]
+ # check status
+ cmd = ['git', 'status', '--short']
proc = Popen(cmd, shell=False, stdin=None, stdout=PIPE, stderr=PIPE, cwd=repodir)
stdout, stderr = proc.communicate()
status = proc.returncode
- if status == 1:
- # check if something was commited
- pattern = 'nothing to commit'
- if stdout.find(pattern) >= 0:
- status = 0
+ # commit
+ if len(stdout) > 0:
+ cmd = ['git', 'commit', '-m', 'commited by trac instance: ' + tracinstancename ]
+ proc = Popen(cmd, shell=False, stdin=None, stdout=PIPE, stderr=PIPE, cwd=repodir)
+ stdout, stderr = proc.communicate()
+ status = proc.returncode
+ if status == 1:
+ # check if something was commited
+ pattern = 'nothing to commit'
+ if stdout.find(pattern) >= 0:
+ status = 0
if status == 0:
# push to gitosis
cmd = ['git', 'push']
proc = Popen(cmd, shell=False, stdin=None, stdout=PIPE, stderr=PIPE, cwd=repodir)
stdout, stderr = proc.communicate()
status = proc.returncode
if status == 0:
- message = stdout
+ message += stdout
else:
- message = stderr
+ message += stdout
+ message += stderr
return status, message

0 comments on commit 0936367

Please sign in to comment.