diff --git a/gcl.py b/gcl.py index 4dfed3389..84819279b 100755 --- a/gcl.py +++ b/gcl.py @@ -831,16 +831,6 @@ def TryChange(change_info, args, swallow_exception): root = os.path.join(root, '') return subpath[len(root):] - # Try to find the gclient root. - def FindGclientRootDir(from_dir): - path = os.path.realpath(from_dir) - while not os.path.exists(os.path.join(path, '.gclient')): - next = os.path.split(path) - if not next[1]: - return None - path = next[0] - return path - trychange_args = [] settings = { 'port': GetCodeReviewSetting('TRYSERVER_HTTP_PORT'), @@ -854,7 +844,7 @@ def TryChange(change_info, args, swallow_exception): if v: trychange_args.extend(['--' + k, v]) - gclient_root = FindGclientRootDir(GetRepositoryRoot()) + gclient_root = gclient_utils.FindGclientRoot(GetRepositoryRoot()) if gclient_root: trychange_args.extend(['--root', PathDifference(gclient_root, GetRepositoryRoot())]) diff --git a/gclient_utils.py b/gclient_utils.py index 4944cf967..97d05edd1 100644 --- a/gclient_utils.py +++ b/gclient_utils.py @@ -307,3 +307,13 @@ def IsUsingGit(root, paths): if os.path.exists(os.path.join(root, path, '.git')): return True return False + +def FindGclientRoot(from_dir): + """Tries to find the gclient root.""" + path = os.path.realpath(from_dir) + while not os.path.exists(os.path.join(path, '.gclient')): + next = os.path.split(path) + if not next[1]: + return None + path = next[0] + return path diff --git a/scm.py b/scm.py index 2e1355588..db4711e36 100644 --- a/scm.py +++ b/scm.py @@ -177,12 +177,17 @@ class GIT(object): return upstream_branch @staticmethod - def GenerateDiff(cwd, branch=None): - """Diffs against the upstream branch or optionally another branch.""" + def GenerateDiff(cwd, branch=None, full_move=False): + """Diffs against the upstream branch or optionally another branch. + + full_move means that move or copy operations should completely recreate the + files, usually in the prospect to apply the patch for a try job.""" if not branch: branch = GIT.GetUpstream(cwd) - diff = GIT.Capture(['diff-tree', '-p', '--no-prefix', branch, 'HEAD'], - cwd).splitlines(True) + command = ['diff-tree', '-p', '--no-prefix', branch, 'HEAD'] + if not full_move: + command.append('-C') + diff = GIT.Capture(command, cwd).splitlines(True) for i in range(len(diff)): # In the case of added files, replace /dev/null with the path to the # file being added. @@ -524,7 +529,9 @@ class SVN(object): """Diffs a single file. Be sure to be in the appropriate directory before calling to have the - expected relative path.""" + expected relative path. + full_move means that move or copy operations should completely recreate the + files, usually in the prospect to apply the patch for a try job.""" # Use svn info output instead of os.path.isdir because the latter fails # when the file is deleted. if SVN.CaptureInfo(filename).get("Node Kind") == "directory": diff --git a/tests/gclient_utils_test.py b/tests/gclient_utils_test.py index c769e2093..bb4e313d2 100644 --- a/tests/gclient_utils_test.py +++ b/tests/gclient_utils_test.py @@ -15,6 +15,7 @@ class GclientUtilsUnittest(SuperMoxTestBase): def testMembersChanged(self): members = [ 'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite', + 'FindGclientRoot', 'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText', 'GetNodeNamedAttributeText', 'IsUsingGit', 'ParseXML', 'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision', diff --git a/tests/trychange_unittest.py b/tests/trychange_unittest.py index 298865cb8..f972040b5 100644 --- a/tests/trychange_unittest.py +++ b/tests/trychange_unittest.py @@ -83,7 +83,8 @@ class GITUnittest(TryChangeTestsBase): def testBasic(self): trychange.os.getcwd().AndReturn(self.fake_root) trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root) - trychange.scm.GIT.GenerateDiff(self.fake_root).AndReturn('a diff') + trychange.scm.GIT.GenerateDiff(self.fake_root, + full_move=True).AndReturn('a diff') trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') self.mox.ReplayAll() diff --git a/trychange.py b/trychange.py index b53a4f5b6..41c7f9f93 100755 --- a/trychange.py +++ b/trychange.py @@ -132,7 +132,8 @@ class GIT(SCM): SCM.__init__(self, *args, **kwargs) self.checkout_root = scm.GIT.GetCheckoutRoot(os.getcwd()) if not self.options.diff: - self.options.diff = scm.GIT.GenerateDiff(self.checkout_root) + self.options.diff = scm.GIT.GenerateDiff(self.checkout_root, + full_move=True) if not self.options.name: self.options.name = scm.GIT.GetPatchName(self.checkout_root) if not self.options.email: