You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2016/01/26 22:52:46 UTC

[2/7] allura git commit: [#8042] ticket:888 Add try/finally constructions into Repo.merge

[#8042] ticket:888 Add try/finally constructions into Repo.merge


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2dd2ff08
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2dd2ff08
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2dd2ff08

Branch: refs/heads/db/8040
Commit: 2dd2ff0811b8e9842ab1091166169b2f1a43e2f3
Parents: 35f84fc
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Jan 22 02:48:19 2016 +0200
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Fri Jan 22 16:00:28 2016 -0500

----------------------------------------------------------------------
 ForgeGit/forgegit/model/git_repo.py             | 40 ++++++++++----------
 .../forgegit/tests/model/test_repository.py     | 10 +++++
 2 files changed, 31 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/2dd2ff08/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 51d300e..7c1bb38 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -117,25 +117,27 @@ class Repository(M.Repository):
         g = self._impl._git.git
         # can't merge in bare repo, so need to clone
         tmp_path = tempfile.mkdtemp()
-        tmp_repo = git.Repo.clone_from(
-            self.full_fs_path,
-            to_path=tmp_path,
-            bare=False)
-        tmp_repo = GitImplementation(Object(full_fs_path=tmp_path))._git
-        tmp_repo.git.fetch('origin', mr.target_branch)
-        tmp_repo.git.checkout(mr.target_branch)
-        tmp_repo.git.fetch(mr.downstream_repo.full_fs_path, mr.source_branch)
-        author = h.really_unicode(c.user.display_name or c.user.username)
-        tmp_repo.git.config('user.name', author)
-        tmp_repo.git.config('user.email', '')
-        msg = u'Merge {} branch {} into {}\n\n{}'.format(
-            mr.downstream_repo.url(),
-            mr.source_branch,
-            mr.target_branch,
-            h.absurl(mr.url()))
-        tmp_repo.git.merge(mr.downstream.commit_id, '-m', msg)
-        tmp_repo.git.push('origin', mr.target_branch)
-        shutil.rmtree(tmp_path, ignore_errors=True)
+        try:
+            tmp_repo = git.Repo.clone_from(
+                self.full_fs_path,
+                to_path=tmp_path,
+                bare=False)
+            tmp_repo = GitImplementation(Object(full_fs_path=tmp_path))._git
+            tmp_repo.git.fetch('origin', mr.target_branch)
+            tmp_repo.git.checkout(mr.target_branch)
+            tmp_repo.git.fetch(mr.downstream_repo.full_fs_path, mr.source_branch)
+            author = h.really_unicode(c.user.display_name or c.user.username)
+            tmp_repo.git.config('user.name', author)
+            tmp_repo.git.config('user.email', '')
+            msg = u'Merge {} branch {} into {}\n\n{}'.format(
+                mr.downstream_repo.url(),
+                mr.source_branch,
+                mr.target_branch,
+                h.absurl(mr.url()))
+            tmp_repo.git.merge(mr.downstream.commit_id, '-m', msg)
+            tmp_repo.git.push('origin', mr.target_branch)
+        finally:
+            shutil.rmtree(tmp_path, ignore_errors=True)
 
     def rev_to_commit_id(self, rev):
         return self._impl.rev_parse(rev).hexsha

http://git-wip-us.apache.org/repos/asf/allura/blob/2dd2ff08/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 2f04bbb..7e9ec4b 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -650,6 +650,16 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
             tempfile.mkdtemp.return_value,
             ignore_errors=True)
 
+    @mock.patch('forgegit.model.git_repo.tempfile')
+    @mock.patch('forgegit.model.git_repo.shutil')
+    @mock.patch('forgegit.model.git_repo.git')
+    def test_merge_raise_exception(self, git, shutil, tempfile):
+        self.repo._impl._git.git = mock.Mock()
+        git.Repo.clone_from.side_effect = Exception
+        with self.assertRaises(Exception):
+            self.repo.merge(mock.Mock())
+        shutil.rmtree.assert_has_calles()
+
     @mock.patch.dict('allura.lib.app_globals.config',  {'scm.commit.git.detect_copies': 'false'})
     @td.with_tool('test', 'Git', 'src-weird', 'Git', type='git')
     def test_paged_diffs(self):