1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 14:52:40 +01:00

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 <git@epriestley.com>
  Date:   Wed Sep 5 14:30:28 2012 -0700

      Edit a text file.

  commit 228d7be4840313ed805c25c15bba0f7b188af3e6
  Author: epriestley <git@epriestley.com>
  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
This commit is contained in:
epriestley 2012-09-21 12:27:21 -07:00
parent 22c51d0d71
commit 95c663f461
2 changed files with 52 additions and 0 deletions

View file

@ -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.

Binary file not shown.