]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add git-repo-based bundle tests
authorepriestley <git@epriestley.com>
Fri, 21 Sep 2012 19:27:21 +0000 (12:27 -0700)
committerepriestley <git@epriestley.com>
Fri, 21 Sep 2012 19:27:21 +0000 (12:27 -0700)
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

src/parser/__tests__/ArcanistBundleTestCase.php
src/parser/__tests__/bundle.git.tgz [new file with mode: 0644]

index e7151b96ac32265e76b85b27dda48e2eaa39b66a..cb52dd68ad825790db996dbe144994de5ad5e145 100644 (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.
diff --git a/src/parser/__tests__/bundle.git.tgz b/src/parser/__tests__/bundle.git.tgz
new file mode 100644 (file)
index 0000000..c3a3fca
Binary files /dev/null and b/src/parser/__tests__/bundle.git.tgz differ