File tree Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 14
14
15
15
use Gitonomy \Git \Util \StringHelper ;
16
16
use Gitonomy \Git \Diff \Diff ;
17
+ use Gitonomy \Git \Exception \ReferenceNotFoundException ;
17
18
18
19
/**
19
20
* Representation of a Git commit.
@@ -139,7 +140,12 @@ private function initialize()
139
140
}
140
141
141
142
$ parser = new Parser \CommitParser ();
142
- $ result = $ this ->repository ->run ('cat-file ' , array ('commit ' , $ this ->hash ));
143
+ try {
144
+ $ result = $ this ->repository ->run ('cat-file ' , array ('commit ' , $ this ->hash ));
145
+ } catch (\RuntimeException $ e ) {
146
+ throw new ReferenceNotFoundException (sprintf ('Can not find reference "%s" ' , $ this ->hash ));
147
+ }
148
+
143
149
$ parser ->parse ($ result );
144
150
145
151
$ this ->treeHash = $ parser ->tree ;
Original file line number Diff line number Diff line change 12
12
13
13
namespace Gitonomy \Git ;
14
14
15
+ use Gitonomy \Git \Exception \ReferenceNotFoundException ;
16
+
15
17
/**
16
18
* @author Alexandre Salomé <[email protected] >
17
19
*/
@@ -57,7 +59,11 @@ public function getResolved()
57
59
return $ this ->resolved ;
58
60
}
59
61
60
- $ result = $ this ->repository ->run ('rev-parse ' , array ('--verify ' , $ this ->name ));
62
+ try {
63
+ $ result = $ this ->repository ->run ('rev-parse ' , array ('--verify ' , $ this ->name ));
64
+ } catch (\RuntimeException $ e ) {
65
+ throw new ReferenceNotFoundException (sprintf ('Can not find reference "%s" ' , $ this ->name ));
66
+ }
61
67
62
68
return $ this ->resolved = $ this ->repository ->getCommit (trim ($ result ));
63
69
}
Original file line number Diff line number Diff line change @@ -39,6 +39,19 @@ public function testGetHash($repository)
39
39
$ this ->assertEquals (self ::LONGFILE_COMMIT , $ commit ->getHash ());
40
40
}
41
41
42
+ /**
43
+ * @dataProvider provideFoobar
44
+ *
45
+ * @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
46
+ * @expectedExceptionMessage Can not find reference "that-hash-doest-not-exists"
47
+ */
48
+ public function testInvalideHashThrowException ($ repository )
49
+ {
50
+ $ commit = new Commit ($ repository , 'that-hash-doest-not-exists ' );
51
+
52
+ $ commit ->getTreeHash ();
53
+ }
54
+
42
55
/**
43
56
* @dataProvider provideFoobar
44
57
*/
Original file line number Diff line number Diff line change @@ -34,6 +34,16 @@ public function testGetCommit($repository)
34
34
$ this ->assertEquals (self ::BEFORE_LONGFILE_COMMIT , $ commit ->getHash (), "Resolution is correct " );
35
35
}
36
36
37
+ /**
38
+ * @dataProvider provideFoobar
39
+ * @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
40
+ * @expectedExceptionMessage Can not find reference "non-existent-commit"
41
+ */
42
+ public function testGetFailingReference ($ repository )
43
+ {
44
+ $ revision = $ repository ->getRevision ('non-existent-commit ' )->getResolved ();
45
+ }
46
+
37
47
/**
38
48
* @dataProvider provideFoobar
39
49
*/
You can’t perform that action at this time.
0 commit comments