From: epriestley Date: Fri, 21 Sep 2012 19:27:21 +0000 (-0700) Subject: Add git-repo-based bundle tests X-Git-Tag: conduit-6~112 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=95c663f461b588f817edfa529663ad8ce75491cb;p=arcanist.git Add git-repo-based bundle tests Summary: Adds a test which goes through a git repository commit by commit and applies them (in effect) via "arc patch", verifying that the results match the actual commit. See D3439 for the fixture stuff. The git repo archive has a couple of trivial commits in it: $ ../libphutil/scripts/utils/directory_fixture.php src/parser/__tests__/bundle.git.tgz Spawning an interactive shell. Exit when complete. sh-3.2$ git log commit f19fb9fa1385c01b53bdb6d8842dd154e47151ec Author: epriestley Date: Wed Sep 5 14:30:28 2012 -0700 Edit a text file. commit 228d7be4840313ed805c25c15bba0f7b188af3e6 Author: epriestley Date: Wed Sep 5 14:30:11 2012 -0700 Add a text file. Test Plan: Ran tests. Reviewers: edward Reviewed By: edward CC: aran Maniphest Tasks: T866 Differential Revision: https://secure.phabricator.com/D3440 --- diff --git a/src/parser/__tests__/ArcanistBundleTestCase.php b/src/parser/__tests__/ArcanistBundleTestCase.php index e7151b96..cb52dd68 100644 --- a/src/parser/__tests__/ArcanistBundleTestCase.php +++ b/src/parser/__tests__/ArcanistBundleTestCase.php @@ -45,6 +45,58 @@ final class ArcanistBundleTestCase extends ArcanistTestCase { return ArcanistBundle::newFromDiff($diff); } + /** + * Unarchive a saved git repository and apply each commit as though via + * "arc patch", verifying that the resulting tree hash is identical to the + * tree hash produced by the real commit. + */ + public function testGitRepository() { + if (phutil_is_windows()) { + $this->assertSkipped('This test is not supported under Windows.'); + } + + $archive = dirname(__FILE__).'/bundle.git.tgz'; + $fixture = PhutilDirectoryFixture::newFromArchive($archive); + + chdir($fixture->getPath()); + + list($commits) = execx( + 'git log --format=%s', + '%H %T %s'); + $commits = explode("\n", trim($commits)); + + // The very first commit doesn't have a meaningful parent, so don't examine + // it. + array_pop($commits); + + foreach ($commits as $commit) { + list($commit_hash, $tree_hash, $subject) = explode(' ', $commit, 3); + list($diff) = execx( + 'git diff %s^ %s --', + $commit_hash, + $commit_hash); + + $parser = new ArcanistDiffParser(); + $changes = $parser->parseDiff($diff); + $bundle = ArcanistBundle::newFromChanges($changes); + + execx('git reset --hard %s^ --', $commit_hash); + + id(new ExecFuture('git apply --index --reject')) + ->write($bundle->toGitPatch()) + ->resolvex(); + + execx('git commit -m %s', $subject); + list($result_hash) = execx('git log -n1 --format=%s', '%T'); + $result_hash = trim($result_hash); + + $this->assertEqual( + $tree_hash, + $result_hash, + "Commit {$commit_hash}: {$subject}"); + } + } + public function testTrailingContext() { // Diffs need to generate without extra trailing context, or 'patch' will // choke on them. diff --git a/src/parser/__tests__/bundle.git.tgz b/src/parser/__tests__/bundle.git.tgz new file mode 100644 index 00000000..c3a3fcac Binary files /dev/null and b/src/parser/__tests__/bundle.git.tgz differ