2017-10-28 00:08:50 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# Copyright (c) 2004-present, Facebook, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This source code is licensed under the BSD-style license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
|
|
|
import logging
|
2017-11-08 05:47:42 +03:00
|
|
|
from .lib.hg_extension_test_base import EdenHgTestCase, hg_test
|
2017-10-28 00:08:50 +03:00
|
|
|
|
|
|
|
log = logging.getLogger('eden.test.absorb')
|
|
|
|
|
|
|
|
|
|
|
|
@hg_test
|
2017-11-08 05:47:42 +03:00
|
|
|
class AbsorbTest(EdenHgTestCase):
|
2017-10-28 00:08:50 +03:00
|
|
|
def populate_backing_repo(self, repo):
|
|
|
|
repo.write_file('readme.txt', 'readme\n')
|
|
|
|
repo.write_file('src/test.c', '''\
|
|
|
|
start of the file
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
end of the file
|
|
|
|
''')
|
|
|
|
self.commit1 = repo.commit('Initial commit.')
|
|
|
|
repo.hg('phase', '--public', self.commit1)
|
|
|
|
log.debug('commit1: %s', self.commit1)
|
|
|
|
|
|
|
|
def test_absorb(self):
|
|
|
|
self.assert_status_empty()
|
|
|
|
|
|
|
|
# Update src/test.c in our first draft commit
|
|
|
|
self.write_file('src/test.c', '''\
|
|
|
|
start of the file
|
|
|
|
line 1
|
|
|
|
new line a
|
|
|
|
line 2
|
|
|
|
new line b
|
|
|
|
line 3
|
|
|
|
end of the file
|
|
|
|
''')
|
|
|
|
self.assert_status({'src/test.c': 'M'})
|
|
|
|
commit2 = self.repo.commit('new lines in test.c\n')
|
|
|
|
self.assert_status_empty()
|
|
|
|
log.debug('commit2: %s', commit2)
|
|
|
|
|
|
|
|
# Update src/new.c in our second draft commit
|
|
|
|
self.write_file('src/new.c', '''\
|
|
|
|
this is a brand new file
|
|
|
|
with some new contents
|
|
|
|
last line
|
|
|
|
''')
|
|
|
|
self.hg('add', 'src/new.c')
|
|
|
|
self.assert_status({'src/new.c': 'A'})
|
|
|
|
commit3 = self.repo.commit('add new.c\n')
|
|
|
|
self.assert_status_empty()
|
|
|
|
log.debug('commit2: %s', commit3)
|
|
|
|
|
|
|
|
# Now modify test.c and new.c in the working copy
|
|
|
|
self.write_file('src/test.c', '''\
|
|
|
|
start of the file
|
|
|
|
line 1
|
|
|
|
new line abc
|
|
|
|
testing
|
|
|
|
line 2
|
|
|
|
new line b
|
|
|
|
line 3
|
|
|
|
end of the file
|
|
|
|
''')
|
|
|
|
self.write_file('src/new.c', '''\
|
|
|
|
this is a brand new file
|
|
|
|
with some enhanced new contents
|
|
|
|
last line
|
|
|
|
''')
|
|
|
|
self.assert_status({'src/new.c': 'M', 'src/test.c': 'M'})
|
|
|
|
old_commits = self.repo.log()
|
|
|
|
|
|
|
|
# Run "hg absorb" to fold these changes into their respective commits
|
|
|
|
out = self.hg('absorb', '-p')
|
|
|
|
log.debug('absorb output:\n%s' % (out,))
|
|
|
|
self.assert_status_empty()
|
|
|
|
|
|
|
|
# Verify the results are what we expect
|
|
|
|
new_commits = self.repo.log()
|
|
|
|
files_changed = self.repo.log(template='{files}')
|
|
|
|
self.assertEqual(len(old_commits), len(new_commits))
|
|
|
|
self.assertEqual(old_commits[0], new_commits[0])
|
|
|
|
self.assertNotEqual(old_commits[1], new_commits[1])
|
|
|
|
self.assertNotEqual(old_commits[2], new_commits[2])
|
|
|
|
self.assertEqual(files_changed[0], 'readme.txt src/test.c')
|
|
|
|
self.assertEqual(files_changed[1], 'src/test.c')
|
|
|
|
self.assertEqual(files_changed[2], 'src/new.c')
|
|
|
|
|
|
|
|
self.assertEqual(self.read_file('src/test.c'), '''\
|
|
|
|
start of the file
|
|
|
|
line 1
|
|
|
|
new line abc
|
|
|
|
testing
|
|
|
|
line 2
|
|
|
|
new line b
|
|
|
|
line 3
|
|
|
|
end of the file
|
|
|
|
''')
|
|
|
|
self.assertEqual(self.read_file('src/new.c'), '''\
|
|
|
|
this is a brand new file
|
|
|
|
with some enhanced new contents
|
|
|
|
last line
|
|
|
|
''')
|