From 68cea21f5384e184bb3fc2c33e5d2213721d6bf5 Mon Sep 17 00:00:00 2001 From: Thomas Meyer Date: Thu, 19 Nov 2015 23:14:03 +0100 Subject: [PATCH] git rev-parse: Add --verify option Add the --verify option to be more compatible with git Change-Id: I225a36ecc4711fd2eb9af67ca8fb79681d94c587 Signed-off-by: Thomas Meyer --- .../jgit/pgm/internal/CLIText.properties | 1 + .../src/org/eclipse/jgit/pgm/RevParse.java | 18 +++++++++++++++--- .../org/eclipse/jgit/pgm/internal/CLIText.java | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties index 64afdad51e..aa32478ff0 100644 --- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties +++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties @@ -128,6 +128,7 @@ metaVar_user=USER metaVar_version=VERSION mostCommonlyUsedCommandsAre=The most commonly used commands are: needApprovalToDestroyCurrentRepository=Need approval to destroy current repository +needSingleRevision=Needed a single revision noGitRepositoryConfigured=No Git repository configured. noNamesFound=No names found, cannot describe anything. noSuchFile=no such file: {0} diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java index 5530ac5c99..4456fd5348 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java @@ -1,6 +1,7 @@ /* * Copyright (C) 2009, Daniel Cheng (aka SDiZ) * Copyright (C) 2009, Daniel Cheng (aka SDiZ) + * Copyright (C) 2015 Thomas Meyer * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -51,14 +52,19 @@ import java.util.List; import java.util.Map; import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.Option; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.pgm.internal.CLIText;; @Command(usage = "usage_RevParse") class RevParse extends TextBuiltin { @Option(name = "--all", usage = "usage_RevParseAll") - boolean all = false; + boolean all; + + @Option(name = "--verify", usage = "usage_RevParseVerify") + boolean verify; @Argument(index = 0, metaVar = "metaVar_commitish") private final List commits = new ArrayList(); @@ -67,11 +73,17 @@ class RevParse extends TextBuiltin { protected void run() throws Exception { if (all) { Map allRefs = db.getRefDatabase().getRefs(ALL); - for (final Ref r : allRefs.values()) + for (final Ref r : allRefs.values()) { outw.println(r.getObjectId().name()); + } } else { - for (final ObjectId o : commits) + if (verify && commits.size() > 1) { + throw new CmdLineException(CLIText.get().needSingleRevision); + } + + for (final ObjectId o : commits) { outw.println(o.name()); + } } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java index 433ddf2b13..29d48ebd46 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java @@ -187,6 +187,7 @@ public class CLIText extends TranslationBundle { /***/ public String metaVar_version; /***/ public String mostCommonlyUsedCommandsAre; /***/ public String needApprovalToDestroyCurrentRepository; + /***/ public String needSingleRevision; /***/ public String noGitRepositoryConfigured; /***/ public String noNamesFound; /***/ public String noSuchFile; -- 2.39.5