sapling/eden/integration/hg/graft_test.py
Michael Bolin 28214295bb Add some extra assertions to GraftTest.
Summary:
In practice, if the `hg graft` succeeds in a weird way, `assert_status_empty()`
tells a lot more about what went wrong than the number of commits not matching up.

While here, I also added the following entry to the default `.hgrc` used in integration tests:

```
[ui]
origbackuppath=.hg/origbackups
```

I needed this for the change to `graft_test.py`. As we were already setting this option in
the `histedit_command.py` utility as a one-off and this is the default value of this setting
for our internal Mercurial use at Facebook, it seemed best to make it the default for all
of our integration tests. As such, I removed the one-off setting in `histedit_command.py`.

Reviewed By: simpkins

Differential Revision: D6180342

fbshipit-source-id: 6f0487624a1824459403126997ea52d1a7921feb
2017-10-30 21:38:14 -07:00

99 lines
3.6 KiB
Python

#!/usr/bin/env python3
#
# Copyright (c) 2016-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 os
from .lib.hg_extension_test_base import hg_test
from ..lib import hgrepo
@hg_test
class GraftTest:
def populate_backing_repo(self, repo):
repo.write_file('first.txt', '1')
self.commit1 = repo.commit('Initial commit\n')
def test_graft_conflict_free_commit(self):
# Create a new head.
self.write_file('second.txt', '2')
self.repo.add_file('second.txt')
commit2 = self.repo.commit('Second commit\n')
# Create another new head.
self.repo.update(self.commit1)
self.assertFalse(os.path.exists(self.get_path('second.txt')))
self.write_file('third.txt', '3')
self.repo.add_file('third.txt')
commit3 = self.repo.commit('Third commit\n')
# Perform graft.
self.hg('graft', commit2)
# Verify we end up with the expected stack of commits.
self.assert_status_empty()
commits = self.repo.log()
self.assertEqual(3, len(commits))
self.assertEqual([self.commit1, commit3], commits[:2])
self.assertTrue(os.path.exists(self.get_path('second.txt')))
def test_graft_commit_with_conflict(self):
# Create a new head.
self.write_file('first.txt', '2')
commit2 = self.repo.commit('Updated first.txt.\n')
# Create another new head that modifies first.txt in a different way.
self.repo.update(self.commit1)
self.write_file('first.txt', '3')
commit3 = self.repo.commit('Alternative update to first.txt.\n')
# Attempt graft.
with self.assertRaises(hgrepo.HgError) as context:
self.hg('graft', commit2)
self.assertIn(
(
"warning: conflicts while merging first.txt!"
" (edit, then use 'hg resolve --mark')\n"
" abort: unresolved conflicts, can't continue\n"
), str(context.exception)
)
# Resolve conflict with something completely different.
self.write_file('first.txt', '23')
self.hg('resolve', '--mark', self.get_path('first.txt'))
self.hg('graft', '--continue')
# Verify we end up with the expected stack of commits.
self.assert_status_empty()
commits = self.repo.log()
self.assertEqual(3, len(commits))
self.assertEqual([self.commit1, commit3], commits[:2])
def test_graft_that_removes_a_file(self):
# Create a new head that adds second.txt and removes first.txt.
self.write_file('second.txt', '2')
self.repo.add_file('second.txt')
self.hg('rm', 'first.txt')
commit2 = self.repo.commit('Add second.txt and remove first.txt.')
# Create a separate head that adds third.txt.
self.repo.update(self.commit1)
self.write_file('third.txt', '3')
self.repo.add_file('third.txt')
commit3 = self.repo.commit('Add third.txt.')
# Perform the graft and verify we end up in the right state.
self.hg('graft', commit2)
self.assert_status_empty()
commits = self.repo.log()
self.assertEqual(3, len(commits))
self.assertEqual([self.commit1, commit3], commits[:2])
self.assertFalse(os.path.exists(self.get_path('first.txt')))
self.assertTrue(os.path.exists(self.get_path('second.txt')))
self.assertTrue(os.path.exists(self.get_path('third.txt')))