diff options
author | Tomasz Zarna <tomasz.zarna@tasktop.com> | 2012-10-29 16:21:59 +0100 |
---|---|---|
committer | Tomasz Zarna <tomasz.zarna@tasktop.com> | 2012-11-16 11:04:13 +0100 |
commit | 318f3d464307e3efd8342852310c17e71a7282fe (patch) | |
tree | bcd251a7110555cd46c5ab18e5e673f52c214cd2 /org.eclipse.jgit.pgm/src | |
parent | cb0f0ad4cfe2733ff09c2ce4d3b72265ccfee281 (diff) | |
download | jgit-318f3d464307e3efd8342852310c17e71a7282fe.tar.gz jgit-318f3d464307e3efd8342852310c17e71a7282fe.zip |
Add support for --no-ff while merging
Bug: 394432
Change-Id: I373128c0ba949f9b24248874f77f3d68b50ccfd1
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java | 3 | ||||
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java | 59 |
2 files changed, 58 insertions, 4 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java index c1cac71cfa..5a0b8b2875 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java @@ -86,6 +86,7 @@ public class CLIText extends TranslationBundle { /***/ public String configFileNotFound; /***/ public String cannotBeRenamed; /***/ public String cannotChekoutNoHeadsAdvertisedByRemote; + /***/ public String cannotCombineSquashWithNoff; /***/ public String cannotCreateCommand; /***/ public String cannotCreateOutputStream; /***/ public String cannotDeatchHEAD; @@ -122,6 +123,7 @@ public class CLIText extends TranslationBundle { /***/ public String fatalError; /***/ public String fatalThisProgramWillDestroyTheRepository; /***/ public String fileIsRequired; + /***/ public String ffNotPossibleAborting; /***/ public String forcedUpdate; /***/ public String fromURI; /***/ public String initializedEmptyGitRepositoryIn; @@ -221,5 +223,6 @@ public class CLIText extends TranslationBundle { /***/ public String unmergedPaths; /***/ public String unsupportedOperation; /***/ public String untrackedFiles; + /***/ public String updating; /***/ public String warningNoCommitGivenOnCommandLine; } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java index 728866d182..e79a8ff0a8 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java @@ -43,14 +43,22 @@ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.text.MessageFormat; import java.util.Map; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.MergeCommand; import org.eclipse.jgit.api.MergeResult; +import org.eclipse.jgit.api.MergeCommand.FastForwardMode; +import org.eclipse.jgit.lib.AnyObjectId; +import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.merge.MergeStrategy; import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevWalk; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -68,8 +76,23 @@ class Merge extends TextBuiltin { @Argument(required = true) private String ref; + @Option(name = "--ff") + private FastForwardMode ff = FastForwardMode.FF; + + @Option(name = "--no-ff") + void noff(@SuppressWarnings("unused") final boolean ignored) { + ff = FastForwardMode.NO_FF; + } + + @Option(name = "--ff-only") + void ffonly(@SuppressWarnings("unused") final boolean ignored) { + ff = FastForwardMode.FF_ONLY; + } + @Override protected void run() throws Exception { + if (squash && ff == FastForwardMode.NO_FF) + throw die(CLIText.get().cannotCombineSquashWithNoff); // determine the merge strategy if (strategyName != null) { mergeStrategy = MergeStrategy.get(strategyName); @@ -79,14 +102,21 @@ class Merge extends TextBuiltin { } // determine the other revision we want to merge with HEAD + final Ref srcRef = db.getRef(ref); final ObjectId src = db.resolve(ref + "^{commit}"); if (src == null) throw die(MessageFormat.format( CLIText.get().refDoesNotExistOrNoCommit, ref)); + Ref oldHead = db.getRef(Constants.HEAD); Git git = new Git(db); - MergeResult result = git.merge().setStrategy(mergeStrategy) - .setSquash(squash).include(src).call(); + MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy) + .setSquash(squash).setFastForward(ff); + if (srcRef != null) + mergeCmd.include(srcRef); + else + mergeCmd.include(src); + MergeResult result = mergeCmd.call(); switch (result.getMergeStatus()) { case ALREADY_UP_TO_DATE: @@ -95,6 +125,10 @@ class Merge extends TextBuiltin { outw.println(CLIText.get().alreadyUpToDate); break; case FAST_FORWARD: + ObjectId oldHeadId = oldHead.getObjectId(); + outw.println(MessageFormat.format(CLIText.get().updating, oldHeadId + .abbreviate(7).name(), result.getNewHead().abbreviate(7) + .name())); outw.println(result.getMergeStatus().toString()); break; case CONFLICTING: @@ -119,15 +153,32 @@ class Merge extends TextBuiltin { } break; case MERGED: - outw.println(MessageFormat.format(CLIText.get().mergeMadeBy, - mergeStrategy.getName())); + String name; + if (!isMergedInto(oldHead, src)) + name = mergeStrategy.getName(); + else + name = "recursive"; + outw.println(MessageFormat.format(CLIText.get().mergeMadeBy, name)); break; case MERGED_SQUASHED: outw.println(CLIText.get().mergedSquashed); break; + case ABORTED: + throw die(CLIText.get().ffNotPossibleAborting); case NOT_SUPPORTED: outw.println(MessageFormat.format( CLIText.get().unsupportedOperation, result.toString())); } } + + private boolean isMergedInto(Ref oldHead, AnyObjectId src) + throws IOException { + RevWalk revWalk = new RevWalk(db); + ObjectId oldHeadObjectId = oldHead.getPeeledObjectId(); + if (oldHeadObjectId == null) + oldHeadObjectId = oldHead.getObjectId(); + RevCommit oldHeadCommit = revWalk.lookupCommit(oldHeadObjectId); + RevCommit srcCommit = revWalk.lookupCommit(src); + return revWalk.isMergedInto(oldHeadCommit, srcCommit); + } } |