Commit b2b46317 authored by nasser@codeaurora.org's avatar nasser@codeaurora.org

Make gclient.git.revert reset to DEPS revision

BUG=http://crosbug.com/2897

Review URL: http://codereview.chromium.org/1742017

Change-Id: I1398a349f1af728b593f0d4ea877831f25aed1f4

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@46113 0039d316-1c4b-4281-b951-d872f2087c98
parent 668ef5a2
......@@ -403,9 +403,16 @@ class GitWrapper(SCMWrapper):
print("\n_____ %s is missing, synching instead" % self.relpath)
# Don't reuse the args.
return self.update(options, [], file_list)
merge_base = self._Run(['merge-base', 'HEAD', 'origin'])
files = self._Run(['diff', merge_base, '--name-only']).split()
self._Run(['reset', '--hard', merge_base], redirect_stdout=False)
default_rev = "refs/heads/master"
url, deps_revision = gclient_utils.SplitUrlRevision(self.url)
if not deps_revision:
deps_revision = default_rev
if deps_revision.startswith('refs/heads/'):
deps_revision = deps_revision.replace('refs/heads/', 'origin/')
files = self._Run(['diff', deps_revision, '--name-only']).split()
self._Run(['reset', '--hard', deps_revision], redirect_stdout=False)
file_list.extend([os.path.join(self.checkout_path, f) for f in files])
def revinfo(self, options, args, file_list):
......
......@@ -527,10 +527,12 @@ from :3
return
options = self.Options()
file_path = gclient_scm.os.path.join(self.base_path, 'a')
gclient_scm.os.remove(file_path)
scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
file_list = []
scm.update(options, None, file_list)
gclient_scm.os.remove(file_path)
file_list = []
scm.revert(options, self.args, file_list)
self.assertEquals(file_list, [file_path])
file_list = []
......@@ -544,41 +546,47 @@ from :3
scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
file_list = []
scm.update(options, None, file_list)
file_list = []
scm.revert(options, self.args, file_list)
self.assertEquals(file_list, [])
self.assertEquals(scm.revinfo(options, self.args, None),
'069c602044c5388d2d15c3f875b057c852003458')
'a7142dc9f0009350b96a11f372b6ea658592aa95')
def testRevertModified(self):
if not self.enabled:
return
options = self.Options()
file_path = gclient_scm.os.path.join(self.base_path, 'a')
open(file_path, 'a').writelines('touched\n')
scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
file_list = []
scm.update(options, None, file_list)
file_path = gclient_scm.os.path.join(self.base_path, 'a')
open(file_path, 'a').writelines('touched\n')
file_list = []
scm.revert(options, self.args, file_list)
self.assertEquals(file_list, [file_path])
file_list = []
scm.diff(options, self.args, file_list)
self.assertEquals(file_list, [])
self.assertEquals(scm.revinfo(options, self.args, None),
'069c602044c5388d2d15c3f875b057c852003458')
'a7142dc9f0009350b96a11f372b6ea658592aa95')
def testRevertNew(self):
if not self.enabled:
return
options = self.Options()
scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
file_list = []
scm.update(options, None, file_list)
file_path = gclient_scm.os.path.join(self.base_path, 'c')
f = open(file_path, 'w')
f.writelines('new\n')
f.close()
Popen(['git', 'add', 'c'], stdout=PIPE,
stderr=STDOUT, cwd=self.base_path).communicate()
scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
file_list = []
scm.revert(options, self.args, file_list)
self.assertEquals(file_list, [file_path])
......@@ -586,7 +594,7 @@ from :3
scm.diff(options, self.args, file_list)
self.assertEquals(file_list, [])
self.assertEquals(scm.revinfo(options, self.args, None),
'069c602044c5388d2d15c3f875b057c852003458')
'a7142dc9f0009350b96a11f372b6ea658592aa95')
def testStatusNew(self):
if not self.enabled:
......
......@@ -28,7 +28,7 @@ class RootTestCase(BaseSCMTestCase):
members = [
'GetCasedPath', 'GIT', 'SVN', 'ValidateEmail',
'gclient_utils', 'glob', 'os', 're', 'shutil', 'subprocess', 'sys',
'tempfile', 'xml',
'tempfile', 'time', 'xml',
]
# If this test fails, you should add the relevant test.
self.compareMembers(scm, members)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment