You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Describe.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2013, Matthias Sohn <matthias.sohn@sap.com> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.pgm;
  11. import java.io.IOException;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import org.eclipse.jgit.api.DescribeCommand;
  15. import org.eclipse.jgit.api.Git;
  16. import org.eclipse.jgit.api.errors.GitAPIException;
  17. import org.eclipse.jgit.api.errors.RefNotFoundException;
  18. import org.eclipse.jgit.errors.InvalidPatternException;
  19. import org.eclipse.jgit.lib.ObjectId;
  20. import org.eclipse.jgit.pgm.internal.CLIText;
  21. import org.kohsuke.args4j.Argument;
  22. import org.kohsuke.args4j.Option;
  23. @Command(common = true, usage = "usage_Describe")
  24. class Describe extends TextBuiltin {
  25. @Argument(index = 0, metaVar = "metaVar_treeish")
  26. private ObjectId tree;
  27. @Option(name = "--long", usage = "usage_LongFormat")
  28. private boolean longDesc;
  29. @Option(name = "--all", usage = "usage_UseTags")
  30. private boolean useAll;
  31. @Option(name = "--tags", usage = "usage_UseTags")
  32. private boolean useTags;
  33. @Option(name = "--always", usage = "usage_AlwaysFallback")
  34. private boolean always;
  35. @Option(name = "--match", usage = "usage_Match", metaVar = "metaVar_pattern")
  36. private List<String> patterns = new ArrayList<>();
  37. /** {@inheritDoc} */
  38. @Override
  39. protected void run() {
  40. try (Git git = new Git(db)) {
  41. DescribeCommand cmd = git.describe();
  42. if (tree != null) {
  43. cmd.setTarget(tree);
  44. }
  45. cmd.setLong(longDesc);
  46. cmd.setAll(useAll);
  47. cmd.setTags(useTags);
  48. cmd.setAlways(always);
  49. cmd.setMatch(patterns.toArray(new String[0]));
  50. String result = null;
  51. try {
  52. result = cmd.call();
  53. } catch (RefNotFoundException e) {
  54. throw die(CLIText.get().noNamesFound, e);
  55. }
  56. if (result == null) {
  57. throw die(CLIText.get().noNamesFound);
  58. }
  59. outw.println(result);
  60. } catch (IOException | InvalidPatternException | GitAPIException e) {
  61. throw die(e.getMessage(), e);
  62. }
  63. }
  64. }