From cc57eb13a7f7a4fd98d8cee97528919618202d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sun, 4 Jan 2026 19:54:46 +0100 Subject: [PATCH] Git: Improve handling of ambigous ID input in checkout dialog In the checkout dialog users can enter object ids manually. As git allows using truncated IDs as identifiers, subsets of the complete id are valid inputs. When these are resolved an the id-part can't be resolved to a single object a dialog pops out telling users, that the commit does not exist. a) The message is wrong. An object with that abreviated id exists, it is just not one, but multiple. b) For the commit dialog the dialog stops the user while typing. This makes entering object id arkward. Both points are addressed here. Observed exception (causing the dialog): INFO [org.netbeans.modules.git]: The given id [7b] is not a commit or an annotated tag. org.eclipse.jgit.errors.AmbiguousObjectException: Object abbreviation 7b is ambiguous at org.eclipse.jgit.lib.Repository.resolveAbbreviation(Repository.java:925) at org.eclipse.jgit.lib.Repository.resolveSimple(Repository.java:853) at org.eclipse.jgit.lib.Repository.resolve(Repository.java:818) at org.eclipse.jgit.lib.Repository.resolve(Repository.java:474) at org.netbeans.libs.git.jgit.Utils.parseObjectId(Utils.java:286) Caused: org.netbeans.libs.git.GitException: The given id [7b] is not a commit or an annotated tag. at org.netbeans.libs.git.jgit.Utils.parseObjectId(Utils.java:290) at org.netbeans.libs.git.jgit.Utils.findCommit(Utils.java:265) at org.netbeans.libs.git.jgit.Utils.findCommit(Utils.java:261) at org.netbeans.libs.git.jgit.commands.LogCommand.run(LogCommand.java:109) at org.netbeans.libs.git.jgit.commands.GitCommand$1.run(GitCommand.java:56) at org.netbeans.libs.git.jgit.commands.GitCommand$1.run(GitCommand.java:53) at java.base/java.security.AccessController.doPrivileged(AccessController.java:251) at org.netbeans.libs.git.jgit.commands.GitCommand.execute(GitCommand.java:53) at org.netbeans.libs.git.GitClient.log(GitClient.java:941) at org.netbeans.modules.git.client.GitClient$38.call(GitClient.java:603) at org.netbeans.modules.git.client.GitClient$38.call(GitClient.java:599) at org.netbeans.modules.git.client.GitClient$CommandInvoker$1$1.call(GitClient.java:945) at org.netbeans.modules.git.client.GitClient$CommandInvoker$1.call(GitClient.java:968) at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethodIntern(GitClient.java:980) at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethod(GitClient.java:909) at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethod(GitClient.java:887) at org.netbeans.modules.git.client.GitClient.log(GitClient.java:599) [catch] at org.netbeans.modules.git.ui.repository.RevisionInfoPanelController$LoadInfoWorker.run(RevisionInfoPanelController.java:179) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1403) at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45) at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2018) --- .../modules/git/ui/repository/RevisionInfoPanelController.java | 3 ++- ide/libs.git/src/org/netbeans/libs/git/jgit/Bundle.properties | 2 +- ide/libs.git/src/org/netbeans/libs/git/jgit/Utils.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ide/git/src/org/netbeans/modules/git/ui/repository/RevisionInfoPanelController.java b/ide/git/src/org/netbeans/modules/git/ui/repository/RevisionInfoPanelController.java index 1cd5cb40ecd2..ba2b4373e35e 100644 --- a/ide/git/src/org/netbeans/modules/git/ui/repository/RevisionInfoPanelController.java +++ b/ide/git/src/org/netbeans/modules/git/ui/repository/RevisionInfoPanelController.java @@ -25,6 +25,7 @@ import java.io.File; import java.text.DateFormat; import java.util.Date; +import org.eclipse.jgit.errors.AmbiguousObjectException; import org.netbeans.modules.git.client.GitClient; import org.netbeans.libs.git.GitException; import org.netbeans.libs.git.GitRevisionInfo; @@ -182,7 +183,7 @@ public void run () { mergedStatus = commonAncestor != null && commonAncestor.getRevision().equals(revisionInfo.getRevision()); } } catch (GitException ex) { - if (!(ex instanceof GitException.MissingObjectException)) { + if (!(ex instanceof GitException.MissingObjectException || ex.getCause() instanceof AmbiguousObjectException)) { GitClientExceptionHandler.notifyException(ex, true); } revisionInfo = null; diff --git a/ide/libs.git/src/org/netbeans/libs/git/jgit/Bundle.properties b/ide/libs.git/src/org/netbeans/libs/git/jgit/Bundle.properties index dd4408f81b1e..81064be592e0 100644 --- a/ide/libs.git/src/org/netbeans/libs/git/jgit/Bundle.properties +++ b/ide/libs.git/src/org/netbeans/libs/git/jgit/Bundle.properties @@ -16,4 +16,4 @@ # under the License. MSG_Exception_IdNotACommit = The given id [{0}] is not a commit or an annotated tag. -MSG_Exception_IdNotUnique = Given objectId [{0}] is not unique. \ No newline at end of file +MSG_Exception_IdAmbiguous = The given objectId [{0}] is ambiguous. \ No newline at end of file diff --git a/ide/libs.git/src/org/netbeans/libs/git/jgit/Utils.java b/ide/libs.git/src/org/netbeans/libs/git/jgit/Utils.java index 9a37e9c752c9..1133ea56e000 100644 --- a/ide/libs.git/src/org/netbeans/libs/git/jgit/Utils.java +++ b/ide/libs.git/src/org/netbeans/libs/git/jgit/Utils.java @@ -287,7 +287,7 @@ public static ObjectId parseObjectId (Repository repository, String objectId) th } catch (RevisionSyntaxException ex) { throw new GitException.MissingObjectException(objectId, GitObjectType.COMMIT, ex); } catch (AmbiguousObjectException ex) { - throw new GitException(MessageFormat.format(Utils.getBundle(Utils.class).getString("MSG_Exception_IdNotACommit"), objectId), ex); //NOI18N + throw new GitException(MessageFormat.format(Utils.getBundle(Utils.class).getString("MSG_Exception_IdAmbiguous"), objectId), ex); //NOI18N } catch (IOException ex) { throw new GitException(ex); }