Correctly handle situation when there are no updates

This commit is contained in:
Michal Čihař 2012-03-05 10:35:20 +01:00
parent 93d3f7e288
commit 0189235122
2 changed files with 12 additions and 3 deletions

View File

@ -291,12 +291,17 @@ class Translation(models.Model):
Commits translation to git. Commits translation to git.
''' '''
repo = self.subproject.get_repo() repo = self.subproject.get_repo()
status = repo.git.status('--porcelain', '--', self.filename)
if status == '':
# No changes to commit
return False
logger.info('Commiting %s as %s', self.filename, author) logger.info('Commiting %s as %s', self.filename, author)
repo.git.commit( repo.git.commit(
self.filename, self.filename,
author = author, author = author,
m = settings.COMMIT_MESSAGE m = settings.COMMIT_MESSAGE
) )
return True
def update_unit(self, unit, request): def update_unit(self, unit, request):
''' '''
@ -380,8 +385,9 @@ class Translation(models.Model):
unit1.merge(unit2, overwrite=overwrite) unit1.merge(unit2, overwrite=overwrite)
store1.save() store1.save()
author = u'%s <%s>' % (request.user.get_full_name(), request.user.email) author = u'%s <%s>' % (request.user.get_full_name(), request.user.email)
self.git_commit(author) ret = self.git_commit(author)
self.check_sync() self.check_sync()
return ret
class Unit(models.Model): class Unit(models.Model):
translation = models.ForeignKey(Translation) translation = models.ForeignKey(Translation)

View File

@ -181,8 +181,11 @@ def upload_translation(request, project, subproject, lang):
form = UploadForm(request.POST, request.FILES) form = UploadForm(request.POST, request.FILES)
if form.is_valid(): if form.is_valid():
try: try:
obj.merge_upload(request, request.FILES['file'], form.cleaned_data['overwrite']) ret = obj.merge_upload(request, request.FILES['file'], form.cleaned_data['overwrite'])
if ret:
messages.add_message(request, messages.INFO, _('File content successfully merged into translation.')) messages.add_message(request, messages.INFO, _('File content successfully merged into translation.'))
else:
messages.add_message(request, messages.INFO, _('There were no new strings in uploaded file.'))
except Exception, e: except Exception, e:
messages.add_message(request, messages.ERROR, _('File content merge failed: %s' % str(e))) messages.add_message(request, messages.ERROR, _('File content merge failed: %s' % str(e)))