From 95c663f461b588f817edfa529663ad8ce75491cb Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 21 Sep 2012 12:27:21 -0700 Subject: [PATCH] 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 --- .../__tests__/ArcanistBundleTestCase.php | 52 ++++++++++++++++++ src/parser/__tests__/bundle.git.tgz | Bin 0 -> 7276 bytes 2 files changed, 52 insertions(+) create mode 100644 src/parser/__tests__/bundle.git.tgz 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 0000000000000000000000000000000000000000..c3a3fcac2e53eb8ca7a8fdd65edbc77a4e0e4adb GIT binary patch literal 7276 zcmV-y9FyZ8iwFRj#79s71MNL)j3h^ScOgKg0gGTP87YGD>~g!aH;?X~p2zNb?|j}n z+Xr_(xCaLA*^la(_RVz9b@$xf;yWx76v&T=5ClpfpeP_EQn-jXaRLgEgjm83!6bx4 z5kv`u7*JjgNMI=fl<%vm?&;~-+u1$u&SKM_v^z6B_4um3_g7!{lqg(o3!v0Ii_dAVO29p7y{|#Sv%{C3T#Sm;t|Eo2S|C&;-W%_>- zAn3n*?C8CZX*LGUlG{-pkS89!v{?}@aY9{}afYYYu)3Z{}r#&xlLeF2dJ-@4mm#H5(o=cX9 zEagx!bUlm0r_k?HDQD$KZ~Yu&FpCD{I0rLpROoBOPNazvl z0pHU^r_615j)IW?`wksAxNUQc_y0%izpQ5VeLs&MXzkv9OL7^^!bmbRh3NtPXZ1eKE4buKLdZe z-*E3^J-imZ-h$WP_D%Ty9Up_QzYmvQ34gcKcfRhP=>y;Y$kA{7;=PLxf9S=(^qF7# z`mUcHoFgfZPC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