Skip to content

Commit 169a1d2

Browse files
juanmcasanovaGrahamCampbell
authored andcommitted
Ignore unknown refs instead of throwing an exception (#161)
1 parent b4620be commit 169a1d2

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

Diff for: src/Gitonomy/Git/ReferenceBag.php

-6
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,6 @@ protected function initialize()
366366
} elseif ($fullname === 'refs/stash') {
367367
$reference = new Stash($this->repository, $fullname, $commitHash);
368368
$this->references[$fullname] = $reference;
369-
} elseif (preg_match('#^refs/pull/(.*)$#', $fullname)) {
370-
// Do nothing here
371-
} elseif ($fullname === 'refs/notes/gtm-data') {
372-
// Do nothing here
373-
} else {
374-
throw new RuntimeException(sprintf('Unable to parse "%s"', $fullname));
375369
}
376370
}
377371
}

Diff for: tests/Gitonomy/Git/Tests/ReferenceBagTest.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Gitonomy.
5+
*
6+
* (c) Alexandre Salomé <[email protected]>
7+
* (c) Julien DIDIER <[email protected]>
8+
*
9+
* This source file is subject to the MIT license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace Gitonomy\Git\Tests;
14+
15+
use Gitonomy\Git\Repository;
16+
17+
class ReferenceBagTest extends AbstractTest
18+
{
19+
/**
20+
* @dataProvider provideFoobar
21+
*/
22+
public function testUnknownReference(Repository $repository)
23+
{
24+
$hash = $repository->getLog()->getSingleCommit()->getHash();
25+
26+
$repository->run('update-ref', ['refs/pipelines/1', $hash]);
27+
$repository->run('update-ref', ['refs/merge-request/1/head', $hash]);
28+
$repository->run('update-ref', ['refs/pull/1/head', $hash]);
29+
$repository->run('update-ref', ['refs/notes/gtm-data', $hash]);
30+
31+
$refs = $repository->getReferences()->getAll();
32+
if (method_exists($this, 'assertIsArray')) {
33+
$this->assertIsArray($refs);
34+
} else {
35+
$this->assertInternalType('array', $refs);
36+
}
37+
38+
// Check that at least it has the master ref
39+
$this->assertArrayHasKey('refs/heads/master', $refs);
40+
41+
// Check that our custom refs have been ignored
42+
$this->assertArrayNotHasKey('refs/pipelines/1', $refs);
43+
$this->assertArrayNotHasKey('refs/merge-request/1/head', $refs);
44+
$this->assertArrayNotHasKey('refs/pull/1/head', $refs);
45+
$this->assertArrayNotHasKey('refs/notes/gtm-data', $refs);
46+
}
47+
}

0 commit comments

Comments
 (0)