From 01892351226f6d6026221d41b649080f637496ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 5 Mar 2012 10:35:20 +0100 Subject: [PATCH] Correctly handle situation when there are no updates --- trans/models.py | 8 +++++++- trans/views.py | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/trans/models.py b/trans/models.py index 71469ee57..0a2f0fff5 100644 --- a/trans/models.py +++ b/trans/models.py @@ -291,12 +291,17 @@ class Translation(models.Model): Commits translation to git. ''' 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) repo.git.commit( self.filename, author = author, m = settings.COMMIT_MESSAGE ) + return True def update_unit(self, unit, request): ''' @@ -380,8 +385,9 @@ class Translation(models.Model): unit1.merge(unit2, overwrite=overwrite) store1.save() author = u'%s <%s>' % (request.user.get_full_name(), request.user.email) - self.git_commit(author) + ret = self.git_commit(author) self.check_sync() + return ret class Unit(models.Model): translation = models.ForeignKey(Translation) diff --git a/trans/views.py b/trans/views.py index 97d793d01..ebb1334c1 100644 --- a/trans/views.py +++ b/trans/views.py @@ -181,8 +181,11 @@ def upload_translation(request, project, subproject, lang): form = UploadForm(request.POST, request.FILES) if form.is_valid(): try: - obj.merge_upload(request, request.FILES['file'], form.cleaned_data['overwrite']) - messages.add_message(request, messages.INFO, _('File content successfully merged into translation.')) + 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.')) + else: + messages.add_message(request, messages.INFO, _('There were no new strings in uploaded file.')) except Exception, e: messages.add_message(request, messages.ERROR, _('File content merge failed: %s' % str(e)))