Replaces RefOptionHandler by RevCommitHandlerOptionHandler.

RefOptionHandler validated any Id that the repository could resolve. It
included Blob and Tree ids. However only id of commits are valid for the
merge and the diff operation.

Change-Id: Ic8625f359ebfa796c93db21fe077d8c1a0e77065
diff --git a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffArgumentsTest.java b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffArgumentsTest.java
index 1a79505..3cb9698 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffArgumentsTest.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffArgumentsTest.java
@@ -78,7 +78,7 @@
 		// Tests the command on an empty repo (not commit, no branch)
 		getContext().addArg(getCommandName(), userSetupFile.getAbsolutePath(), "master");
 		Object result = getApp().start(getContext());
-		assertOutput("fatal: master - not a valid git reference." + EOL);
+		assertOutput("fatal: bad revision 'master'." + EOL);
 		assertEmptyErrorMessage();
 		assertEquals(Returns.ERROR.code(), result);
 	}
@@ -110,7 +110,7 @@
 		// Gives an incorrect ref
 		getContext().addArg(getCommandName(), setupFile.getAbsolutePath(), "incorrectId");
 		Object result = getApp().start(getContext());
-		assertOutput("fatal: incorrectId - not a valid git reference." + EOL);
+		assertOutput("fatal: bad revision 'incorrectId'." + EOL);
 		assertEmptyErrorMessage();
 		assertEquals(Returns.ERROR.code(), result);
 	}
@@ -130,7 +130,7 @@
 		// Gives an incorrect ref
 		getContext().addArg(getCommandName(), setupFile.getAbsolutePath(), "master", "incorrectId");
 		Object result = getApp().start(getContext());
-		assertOutput("fatal: incorrectId - not a valid git reference." + EOL);
+		assertOutput("fatal: bad revision 'incorrectId'." + EOL);
 		assertEmptyErrorMessage();
 		assertEquals(Returns.ERROR.code(), result);
 	}
diff --git a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommandArgumentsTest.java b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommandArgumentsTest.java
index 81485d2..b3046a4 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommandArgumentsTest.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommandArgumentsTest.java
@@ -89,7 +89,7 @@
 		// Tests commant on an empty repo (not commit, no branch)
 		getContext().addArg(getCommandName(), setupFile.getAbsolutePath(), "master");
 		Object result = getApp().start(getContext());
-		assertOutput("fatal: master - not a valid git reference." + EOL);
+		assertOutput("fatal: bad revision 'master'." + EOL);
 		assertEmptyErrorMessage();
 		assertEquals(Returns.ERROR.code(), result);
 	}
@@ -186,7 +186,7 @@
 		// Gives an incorrect ref
 		getContext().addArg(LOGICAL_MERGE_CMD_NAME, newSetupFile.getAbsolutePath(), "incorrectId");
 		Object result = getApp().start(getContext());
-		assertOutput("fatal: incorrectId - not a valid git reference." + EOL);
+		assertOutput("fatal: bad revision 'incorrectId'." + EOL);
 		assertEmptyErrorMessage();
 		assertEquals(Returns.ERROR.code(), result);
 	}
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalDiffApplication.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalDiffApplication.java
index 0804c81..a9dd721 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalDiffApplication.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalDiffApplication.java
@@ -30,7 +30,7 @@
 import org.eclipse.emf.compare.EMFCompare;
 import org.eclipse.emf.compare.git.pgm.Returns;
 import org.eclipse.emf.compare.git.pgm.internal.args.PathFilterHandler;
-import org.eclipse.emf.compare.git.pgm.internal.args.RefOptionHandler;
+import org.eclipse.emf.compare.git.pgm.internal.args.RevCommitOptionHandler;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die.DeathType;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die.DiesOn;
@@ -48,7 +48,7 @@
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.diff.DiffEntry;
-import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.treewalk.filter.PathFilter;
 import org.eclipse.jgit.treewalk.filter.TreeFilter;
 import org.kohsuke.args4j.Argument;
@@ -77,14 +77,14 @@
 	/**
 	 * Holds the reference from which the differences should be displayed.
 	 */
-	@Argument(index = 2, multiValued = false, required = true, metaVar = "<commit>", usage = "Commit ID or branch name.", handler = RefOptionHandler.class)
-	private ObjectId commit;
+	@Argument(index = 2, multiValued = false, required = true, metaVar = "<commit>", usage = "Commit ID or branch name.", handler = RevCommitOptionHandler.class)
+	private RevCommit commit;
 
 	/**
 	 * Optional reference used to view the differences between {@link #commit} and {@link #commitWith}.
 	 */
-	@Argument(index = 3, multiValued = false, required = false, metaVar = "<compareWithCommit>", usage = "Commit ID or branch name. This is to view the changes between <commit> and <compareWithCommit> or HEAD if not specified.", handler = RefOptionHandler.class)
-	private ObjectId commitWith;
+	@Argument(index = 3, multiValued = false, required = false, metaVar = "<compareWithCommit>", usage = "Commit ID or branch name. This is to view the changes between <commit> and <compareWithCommit> or HEAD if not specified.", handler = RevCommitOptionHandler.class)
+	private RevCommit commitWith;
 
 	/**
 	 * {@link TreeFilter} use to filter file on which differences should be shown.
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalMergeApplication.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalMergeApplication.java
index 17b5b55..f785ae9 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalMergeApplication.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalMergeApplication.java
@@ -24,7 +24,7 @@
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.egit.core.op.MergeOperation;
 import org.eclipse.emf.compare.git.pgm.Returns;
-import org.eclipse.emf.compare.git.pgm.internal.args.RefOptionHandler;
+import org.eclipse.emf.compare.git.pgm.internal.args.RevCommitOptionHandler;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die.DeathType;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die.DiesOn;
@@ -38,6 +38,7 @@
 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.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.Option;
 
@@ -70,8 +71,8 @@
 	/**
 	 * Holds a ObjectId that need to be merged.
 	 */
-	@Argument(index = 2, required = true, metaVar = "<commit>", usage = "Commit ID or branch name to merge.", handler = RefOptionHandler.class)
-	private ObjectId commit;
+	@Argument(index = 2, required = true, metaVar = "<commit>", usage = "Commit ID or branch name to merge.", handler = RevCommitOptionHandler.class)
+	private RevCommit commit;
 
 	/**
 	 * Optional message used for the merge commit.
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RefOptionHandler.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RefOptionHandler.java
deleted file mode 100644
index 7cfb9b5..0000000
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RefOptionHandler.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 Obeo.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors:
- *     Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.git.pgm.internal.args;
-
-import com.google.common.base.Preconditions;
-
-import java.io.IOException;
-
-import org.eclipse.emf.compare.git.pgm.internal.exception.ArgumentValidationError;
-import org.eclipse.emf.compare.git.pgm.internal.exception.Die;
-import org.eclipse.jgit.errors.RevisionSyntaxException;
-import org.eclipse.jgit.lib.ObjectId;
-import org.kohsuke.args4j.CmdLineException;
-import org.kohsuke.args4j.CmdLineParser;
-import org.kohsuke.args4j.OptionDef;
-import org.kohsuke.args4j.spi.OptionHandler;
-import org.kohsuke.args4j.spi.Parameters;
-import org.kohsuke.args4j.spi.Setter;
-
-/**
- * OptionHandler that parses a commit reference from a command line and checks that it can be resolved in the
- * git repository of the logical command.
- * 
- * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a>
- */
-public class RefOptionHandler extends OptionHandler<ObjectId> {
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param parser
-	 *            {@link OptionHandler#owner}
-	 * @param option
-	 *            {@link OptionHandler#option}
-	 * @param setter
-	 *            {@link OptionHandler#setter}
-	 */
-	public RefOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super ObjectId> setter) {
-		super(parser, option, setter);
-		Preconditions.checkArgument(parser instanceof CmdLineParserRepositoryBuilder);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 * 
-	 * @see org.kohsuke.args4j.spi.OptionHandler#parseArguments(org.kohsuke.args4j.spi.Parameters)
-	 */
-	@Override
-	public int parseArguments(Parameters params) throws CmdLineException {
-		String ref = params.getParameter(0);
-
-		ObjectId objectID;
-		try {
-			objectID = ((CmdLineParserRepositoryBuilder)owner).getRepo().resolve(ref);
-			setter.addValue(objectID);
-		} catch (RevisionSyntaxException | IOException | Die e) {
-			throw new ArgumentValidationError(owner, e);
-		}
-		if (objectID == null) {
-			throw new ArgumentValidationError(owner, ref + " - not a valid git reference.");
-		}
-		return 1;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 * 
-	 * @see org.kohsuke.args4j.spi.OptionHandler#getDefaultMetaVariable()
-	 */
-	@Override
-	public String getDefaultMetaVariable() {
-		return "commit"; //$NON-NLS-1$
-	}
-
-}
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffCommand.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffCommand.java
index 2c1c332..36459bb 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffCommand.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffCommand.java
@@ -20,12 +20,12 @@
 
 import org.eclipse.emf.compare.git.pgm.Returns;
 import org.eclipse.emf.compare.git.pgm.internal.args.PathFilterHandler;
-import org.eclipse.emf.compare.git.pgm.internal.args.RefOptionHandler;
+import org.eclipse.emf.compare.git.pgm.internal.args.RevCommitOptionHandler;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die.DeathType;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die.DiesOn;
 import org.eclipse.emf.compare.git.pgm.internal.util.EMFCompareGitPGMUtil;
-import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.treewalk.filter.PathFilter;
 import org.eclipse.jgit.treewalk.filter.TreeFilter;
 import org.eclipse.oomph.setup.util.OS;
@@ -61,14 +61,14 @@
 	/**
 	 * Holds the reference from which the differences should be displayed.
 	 */
-	@Argument(index = 1, multiValued = false, required = true, metaVar = "<commit>", usage = "Commit ID or branch name.", handler = RefOptionHandler.class)
-	private ObjectId commit;
+	@Argument(index = 1, multiValued = false, required = true, metaVar = "<commit>", usage = "Commit ID or branch name.", handler = RevCommitOptionHandler.class)
+	private RevCommit commit;
 
 	/**
 	 * Optional reference used to view the differences between {@link #commit} and {@link #commitWith}.
 	 */
-	@Argument(index = 2, multiValued = false, required = false, metaVar = "<compareWithCommit>", usage = "Commit ID or branch name. This is to view the changes between <commit> and <compareWithCommit> or HEAD if not specified.", handler = RefOptionHandler.class)
-	private ObjectId commitWith;
+	@Argument(index = 2, multiValued = false, required = false, metaVar = "<compareWithCommit>", usage = "Commit ID or branch name. This is to view the changes between <commit> and <compareWithCommit> or HEAD if not specified.", handler = RevCommitOptionHandler.class)
+	private RevCommit commitWith;
 
 	/**
 	 * {@link TreeFilter} use to filter file on which differences should be shown.
@@ -178,12 +178,12 @@
 	}
 
 	// For testing purpose
-	ObjectId getCommit() {
+	RevCommit getCommit() {
 		return commit;
 	}
 
 	// For testing purpose
-	ObjectId getOptionalCommit() {
+	RevCommit getOptionalCommit() {
 		return commitWith;
 	}
 
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommand.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommand.java
index aafcf26..79463a2 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommand.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommand.java
@@ -20,13 +20,13 @@
 import java.util.List;
 
 import org.eclipse.emf.compare.git.pgm.Returns;
-import org.eclipse.emf.compare.git.pgm.internal.args.RefOptionHandler;
+import org.eclipse.emf.compare.git.pgm.internal.args.RevCommitOptionHandler;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die.DeathType;
 import org.eclipse.emf.compare.git.pgm.internal.exception.Die.DiesOn;
 import org.eclipse.emf.compare.git.pgm.internal.util.EMFCompareGitPGMUtil;
-import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.RepositoryState;
+import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.oomph.setup.util.OS;
 import org.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.Option;
@@ -60,8 +60,8 @@
 	/**
 	 * Holds a ObjectId that need to be merged.
 	 */
-	@Argument(index = 1, required = true, metaVar = "<commit>", usage = "Commit ID or branch name to merge.", handler = RefOptionHandler.class)
-	private ObjectId commit;
+	@Argument(index = 1, required = true, metaVar = "<commit>", usage = "Commit ID or branch name to merge.", handler = RevCommitOptionHandler.class)
+	private RevCommit commit;
 
 	/**
 	 * Optional message used for the merge commit.
@@ -87,8 +87,7 @@
 		if (getRepository().getRepositoryState() == RepositoryState.MERGING) {
 			StringBuilder msg = new StringBuilder(
 					"error: 'merge' is not possible because you have unmerged files.").append(EOL);
-			msg.append("hint: Use the logicalmergetool command to fix them up un the work tree").append(
-					EOL);
+			msg.append("hint: Use the logicalmergetool command to fix them up un the work tree").append(EOL);
 			msg.append("hint: and then use the 'git add/rm <file>' as").append(EOL);
 			msg.append("hint: appropriate to mark resolution").append(EOL);
 			System.out.println(msg);
@@ -190,7 +189,7 @@
 	}
 
 	// For testing purpose.
-	ObjectId getCommit() {
+	RevCommit getCommit() {
 		return commit;
 	}
 }