Skip to content

Commit c5d2f09

Browse files
committed
merge: Throw GitMergeNoAncesstor if none found
1 parent ceb04b4 commit c5d2f09

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

lib/exceptions.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class GitMergeTooManyBases extends GitException {}
155155

156156
class GitMergeOnHashNotAllowed extends GitException {}
157157

158+
class GitMergeNoCommonAncestor extends GitException {}
159+
158160
class GitNotImplemented extends GitException {}
159161

160162
class GitRepoExists implements GitException {}

lib/merge.dart

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,26 @@ extension Merge on GitRepository {
3636
if (bases.length > 1) {
3737
throw GitMergeTooManyBases();
3838
}
39-
if (bases.isNotEmpty) {
40-
var baseHash = bases.first.hash;
39+
if (bases.isEmpty) {
40+
throw GitMergeNoCommonAncestor();
41+
}
42+
var baseHash = bases.first.hash;
4143

42-
// up to date
43-
if (baseHash == commitB.hash) {
44-
return;
45-
}
44+
// up to date
45+
if (baseHash == commitB.hash) {
46+
return;
47+
}
4648

47-
// fastforward
48-
if (baseHash == headCommit.hash) {
49-
var branchNameRef = headRef.target;
50-
assert(branchNameRef.isBranch());
49+
// fastforward
50+
if (baseHash == headCommit.hash) {
51+
var branchNameRef = headRef.target;
52+
assert(branchNameRef.isBranch());
5153

52-
var newRef = HashReference(branchNameRef, commitB.hash);
53-
refStorage.saveRef(newRef);
54+
var newRef = HashReference(branchNameRef, commitB.hash);
55+
refStorage.saveRef(newRef);
5456

55-
checkout('.');
56-
return;
57-
}
57+
checkout('.');
58+
return;
5859
}
5960

6061
var baseTree = objStorage.readTree(bases.first.treeHash);

0 commit comments

Comments
 (0)