Blob Blame History Raw
From 86475179c6ec5450c3039c7b1296c0b780e2e705 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Wed, 14 May 2014 12:35:31 -0400
Subject: [PATCH 8/8] Properly generate parent diffs in git

The old behavior was to only populate the 'parent_base' attribute
if the 'base' of the review range did not show up with
git branch -r --contains <base>

This fails for many common environments (such as having pushed to
your private github repository prior to posting the review).
Presumably, the assumption that was made is that if the base is
present on a remote branch, it must be already available to
Review Board. With distributed version-control systems, this is
not a safe assumption to make.

With this change, we will always look up the merge base and
compare it to the review base. If they are different, we will pass
along the parent_base so that the parent diff can be generated
correctly.
---
 rbtools/clients/git.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/rbtools/clients/git.py b/rbtools/clients/git.py
index 570ebd9aafecc9cff9ed8739d2d9bfa06bea243f..fee8b873ee16a1127e70c0678ef27b0f015d2f83 100644
--- a/rbtools/clients/git.py
+++ b/rbtools/clients/git.py
@@ -130,11 +130,10 @@ class GitClient(SCMClient):
                 raise InvalidRevisionSpecError(
                     'Unexpected result while parsing revision spec')
 
-            pdiff_required = not execute(
-                [self.git, 'branch', '-r', '--contains', result['base']])
-            if pdiff_required:
-                result['parent_base'] = self._get_merge_base(result['base'],
-                                                             self.upstream_branch)
+            parent_base = self._get_merge_base(result['base'],
+                                               self.upstream_branch)
+            if not parent_base == result['base']:
+                result['parent_base'] = parent_base
         else:
             raise TooManyRevisionsError
 
-- 
1.9.0