Skip to content

Commit 2572a82

Browse files
author
Gabriel Roldan
committed
Add abort flag to MergeOp
Signed-off-by: Gabriel Roldan <[email protected]>
1 parent 313c795 commit 2572a82

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/core/src/main/java/org/locationtech/geogig/plumbing/CleanRefsOp.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,20 @@ public class CleanRefsOp extends AbstractGeoGigOp<ImmutableList<String>> {
3939
@Override
4040
protected ImmutableList<String> _call() {
4141
Builder<String> cleaned = new ImmutableList.Builder<String>();
42-
Optional<Ref> ref = command(RefParse.class).setName(Ref.MERGE_HEAD).call();
42+
Optional<Ref> ref = command(UpdateRef.class).setDelete(true).setName(Ref.MERGE_HEAD).call();
4343
if (ref.isPresent()) {
4444
cleaned.add(Ref.MERGE_HEAD);
45-
command(UpdateRef.class).setDelete(true).setName(Ref.MERGE_HEAD).call();
4645
}
47-
ref = command(RefParse.class).setName(Ref.ORIG_HEAD).call();
46+
ref = command(UpdateRef.class).setDelete(true).setName(Ref.ORIG_HEAD).call();
4847
if (ref.isPresent()) {
4948
cleaned.add(Ref.ORIG_HEAD);
50-
command(UpdateRef.class).setDelete(true).setName(Ref.ORIG_HEAD).call();
5149
}
52-
ref = command(RefParse.class).setName(Ref.CHERRY_PICK_HEAD).call();
50+
ref = command(UpdateRef.class).setDelete(true).setName(Ref.CHERRY_PICK_HEAD).call();
5351
if (ref.isPresent()) {
5452
cleaned.add(Ref.CHERRY_PICK_HEAD);
55-
command(UpdateRef.class).setDelete(true).setName(Ref.CHERRY_PICK_HEAD).call();
5653
}
5754
BlobStore blobStore = context.blobStore();
58-
Optional<String> blob = Blobs.getBlobAsString(blobStore, MergeOp.MERGE_MSG);
55+
Optional<byte[]> blob = Blobs.getBlob(blobStore, MergeOp.MERGE_MSG);
5956
if (blob.isPresent()) {
6057
cleaned.add(MergeOp.MERGE_MSG);
6158
blobStore.removeBlob(MergeOp.MERGE_MSG);

src/core/src/main/java/org/locationtech/geogig/porcelain/MergeOp.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.locationtech.geogig.model.Ref;
2323
import org.locationtech.geogig.model.RevCommit;
2424
import org.locationtech.geogig.model.SymRef;
25+
import org.locationtech.geogig.plumbing.CleanRefsOp;
2526
import org.locationtech.geogig.plumbing.DiffTree;
2627
import org.locationtech.geogig.plumbing.FindCommonAncestor;
2728
import org.locationtech.geogig.plumbing.RefParse;
@@ -61,6 +62,8 @@ public class MergeOp extends AbstractGeoGigOp<MergeOp.MergeReport> {
6162

6263
private boolean theirs;
6364

65+
private boolean continueMerge;
66+
6467
private boolean noCommit;
6568

6669
private boolean noFastForward;
@@ -82,6 +85,8 @@ public class MergeOp extends AbstractGeoGigOp<MergeOp.MergeReport> {
8285

8386
private Ref origStageHead = null;
8487

88+
private boolean abort;
89+
8590
/**
8691
* @param message the message for the merge commit
8792
* @return {@code this}
@@ -106,6 +111,11 @@ public MergeOp addCommit(final ObjectId commit) {
106111
return this;
107112
}
108113

114+
public MergeOp setAbort() {
115+
this.abort = true;
116+
return this;
117+
}
118+
109119
/**
110120
*
111121
* @param ours true if the "ours" strategy should be used
@@ -177,8 +187,11 @@ public MergeOp setFastForwardOnly(boolean fastForwardOnly) {
177187
*/
178188
@Override
179189
protected MergeReport _call() throws RuntimeException {
190+
if (abort) {
191+
return abort();
192+
}
180193
final List<ObjectId> commits = this.commits;
181-
checkArgument(commits.size() > 0, "No commits specified for merge.");
194+
checkArgument(continueMerge || commits.size() > 0, "No commits specified for merge.");
182195
checkArgument(!(ours && theirs), "Cannot use both --ours and --theirs.");
183196
checkArgument(!(noFastForward && fastForwardOnly), "Cannot use both --no-ff and --ff-only");
184197

@@ -349,6 +362,12 @@ protected MergeReport _call() throws RuntimeException {
349362

350363
}
351364

365+
private MergeReport abort() {
366+
command(CleanRefsOp.class).call();
367+
conflictsDatabase().removeConflicts(null);
368+
return null;
369+
}
370+
352371
private Ref doFastForwardMerge(Ref headRef, ObjectId commitId,
353372
MergeStatusBuilder mergeStatusBuilder) {
354373
if (headRef instanceof SymRef) {

0 commit comments

Comments
 (0)