Commit 2d6cc102 authored by Jérome Perrin's avatar Jérome Perrin

testnode/Upgrader: fix update when head is a merge commit

Updater was using this command to find the latest revision modifying a
path:

  git log -1 -- $PATH

but because of git log's history simplificiation [1] when the head of
the branch is a merge commit, the considered revision was not the merge
commit but its parent.

Use --full-history so that git does not simplify history and return the
merge commit if the latest commit is a merge.

[1]: https://git-scm.com/docs/git-log#_history_simplification

See also https://stackoverflow.com/a/50724301/7607763
parent e526130b
......@@ -489,6 +489,48 @@ shared = true
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
self.assertTrue(rev_list is not None)
def test_update_revision_with_head_at_merge(self):
"""Test update revision when the head of the branch is a merge commit.
"""
self.generateTestRepositoryList(add_third_repository=True)
test_node = self.getTestNode()
node_test_suite = test_node.getNodeTestSuite('foo')
self.updateNodeTestSuiteData(node_test_suite, add_third_repository=True)
rev_list = self.getAndUpdateFullRevisionList(test_node, node_test_suite)
self.assertEqual(3, len(rev_list))
self.assertEqual(3, len(node_test_suite.vcs_repository_list))
rep2_remote_path = [x['url'] for x in \
node_test_suite.vcs_repository_list \
if x['url'].endswith("rep2")][0]
call = self.getCaller(cwd=rep2_remote_path)
# make a branch and merge it, to have a topology like this:
#
# o1 -- o2 -- o4
# \ /
# o3
call("git checkout -b test_branch".split())
with open(os.path.join(rep2_remote_path, 'test_file'), 'w') as test_file:
test_file.write("test file !")
call("git add test_file".split())
call("git commit -m added".split())
call("git checkout master".split())
call("git merge --no-ff test_branch".split())
expected_revision = call("git rev-parse HEAD".split()).strip()
# Including the merge, we have 4 commits on this branch, because master is at o4
self.assertEqual(
'4',
call('git rev-list --topo-order --count HEAD'.split()).strip())
vcs_repository_info = node_test_suite.vcs_repository_list[0]
vcs_repository_info['branch'] = 'master'
rev_list = [
rev.split('=') for rev
in self.getAndUpdateFullRevisionList(test_node, node_test_suite)]
self.assertEqual(
["4-" + expected_revision],
[revision for (repository, revision) in rev_list if repository == 'rep2'])
def test_06_checkRevision(self):
"""
Check if we are able to restore older commit hash if master decide so
......
......@@ -143,7 +143,7 @@ class Updater(object):
if not path_list:
path_list = self._path_list
if self.getRepositoryType() == GIT_TYPE:
h = self._git('log', '-1', '--format=%H', '--', *path_list)
h = self._git('log', '-1', '--format=%H', '--full-history', '--', *path_list)
return self._git_find_rev(h)
elif self.getRepositoryType() == SVN_TYPE:
stdout = self.spawn('svn', 'info', *path_list)['stdout']
......
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