diff options
Diffstat (limited to 'org.eclipse.jgit.pgm')
44 files changed, 701 insertions, 383 deletions
diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF index e10a772a8c..a00dc54e50 100644 --- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Automatic-Module-Name: org.eclipse.jgit.pgm Bundle-SymbolicName: org.eclipse.jgit.pgm -Bundle-Version: 5.2.3.qualifier +Bundle-Version: 5.3.6.qualifier Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy Bundle-Localization: plugin @@ -28,50 +28,50 @@ Import-Package: javax.servlet;version="[3.1.0,4.0.0)", org.eclipse.jetty.util.log;version="[9.4.5,10.0.0)", org.eclipse.jetty.util.security;version="[9.4.5,10.0.0)", org.eclipse.jetty.util.thread;version="[9.4.5,10.0.0)", - org.eclipse.jgit.api;version="[5.2.3,5.3.0)", - org.eclipse.jgit.api.errors;version="[5.2.3,5.3.0)", - org.eclipse.jgit.archive;version="[5.2.3,5.3.0)", - org.eclipse.jgit.awtui;version="[5.2.3,5.3.0)", - org.eclipse.jgit.blame;version="[5.2.3,5.3.0)", - org.eclipse.jgit.diff;version="[5.2.3,5.3.0)", - org.eclipse.jgit.dircache;version="[5.2.3,5.3.0)", - org.eclipse.jgit.errors;version="[5.2.3,5.3.0)", - org.eclipse.jgit.gitrepo;version="[5.2.3,5.3.0)", - org.eclipse.jgit.internal.ketch;version="[5.2.3,5.3.0)", - org.eclipse.jgit.internal.storage.dfs;version="[5.2.3,5.3.0)", - org.eclipse.jgit.internal.storage.file;version="[5.2.3,5.3.0)", - org.eclipse.jgit.internal.storage.io;version="[5.2.3,5.3.0)", - org.eclipse.jgit.internal.storage.pack;version="[5.2.3,5.3.0)", - org.eclipse.jgit.internal.storage.reftable;version="[5.2.3,5.3.0)", - org.eclipse.jgit.internal.storage.reftree;version="[5.2.3,5.3.0)", - org.eclipse.jgit.lfs;version="[5.2.3,5.3.0)", - org.eclipse.jgit.lfs.lib;version="[5.2.3,5.3.0)", - org.eclipse.jgit.lfs.server;version="[5.2.3,5.3.0)", - org.eclipse.jgit.lfs.server.fs;version="[5.2.3,5.3.0)", - org.eclipse.jgit.lfs.server.s3;version="[5.2.3,5.3.0)", - org.eclipse.jgit.lib;version="[5.2.3,5.3.0)", - org.eclipse.jgit.merge;version="[5.2.3,5.3.0)", - org.eclipse.jgit.nls;version="[5.2.3,5.3.0)", - org.eclipse.jgit.notes;version="[5.2.3,5.3.0)", - org.eclipse.jgit.revplot;version="[5.2.3,5.3.0)", - org.eclipse.jgit.revwalk;version="[5.2.3,5.3.0)", - org.eclipse.jgit.revwalk.filter;version="[5.2.3,5.3.0)", - org.eclipse.jgit.storage.file;version="[5.2.3,5.3.0)", - org.eclipse.jgit.storage.pack;version="[5.2.3,5.3.0)", - org.eclipse.jgit.transport;version="[5.2.3,5.3.0)", - org.eclipse.jgit.transport.http.apache;version="[5.2.3,5.3.0)", - org.eclipse.jgit.transport.resolver;version="[5.2.3,5.3.0)", - org.eclipse.jgit.transport.sshd;version="[5.2.3,5.3.0)", - org.eclipse.jgit.treewalk;version="[5.2.3,5.3.0)", - org.eclipse.jgit.treewalk.filter;version="[5.2.3,5.3.0)", - org.eclipse.jgit.util;version="[5.2.3,5.3.0)", - org.eclipse.jgit.util.io;version="[5.2.3,5.3.0)", + org.eclipse.jgit.api;version="[5.3.6,5.4.0)", + org.eclipse.jgit.api.errors;version="[5.3.6,5.4.0)", + org.eclipse.jgit.archive;version="[5.3.6,5.4.0)", + org.eclipse.jgit.awtui;version="[5.3.6,5.4.0)", + org.eclipse.jgit.blame;version="[5.3.6,5.4.0)", + org.eclipse.jgit.diff;version="[5.3.6,5.4.0)", + org.eclipse.jgit.dircache;version="[5.3.6,5.4.0)", + org.eclipse.jgit.errors;version="[5.3.6,5.4.0)", + org.eclipse.jgit.gitrepo;version="[5.3.6,5.4.0)", + org.eclipse.jgit.internal.ketch;version="[5.3.6,5.4.0)", + org.eclipse.jgit.internal.storage.dfs;version="[5.3.6,5.4.0)", + org.eclipse.jgit.internal.storage.file;version="[5.3.6,5.4.0)", + org.eclipse.jgit.internal.storage.io;version="[5.3.6,5.4.0)", + org.eclipse.jgit.internal.storage.pack;version="[5.3.6,5.4.0)", + org.eclipse.jgit.internal.storage.reftable;version="[5.3.6,5.4.0)", + org.eclipse.jgit.internal.storage.reftree;version="[5.3.6,5.4.0)", + org.eclipse.jgit.lfs;version="[5.3.6,5.4.0)", + org.eclipse.jgit.lfs.lib;version="[5.3.6,5.4.0)", + org.eclipse.jgit.lfs.server;version="[5.3.6,5.4.0)", + org.eclipse.jgit.lfs.server.fs;version="[5.3.6,5.4.0)", + org.eclipse.jgit.lfs.server.s3;version="[5.3.6,5.4.0)", + org.eclipse.jgit.lib;version="[5.3.6,5.4.0)", + org.eclipse.jgit.merge;version="[5.3.6,5.4.0)", + org.eclipse.jgit.nls;version="[5.3.6,5.4.0)", + org.eclipse.jgit.notes;version="[5.3.6,5.4.0)", + org.eclipse.jgit.revplot;version="[5.3.6,5.4.0)", + org.eclipse.jgit.revwalk;version="[5.3.6,5.4.0)", + org.eclipse.jgit.revwalk.filter;version="[5.3.6,5.4.0)", + org.eclipse.jgit.storage.file;version="[5.3.6,5.4.0)", + org.eclipse.jgit.storage.pack;version="[5.3.6,5.4.0)", + org.eclipse.jgit.transport;version="[5.3.6,5.4.0)", + org.eclipse.jgit.transport.http.apache;version="[5.3.6,5.4.0)", + org.eclipse.jgit.transport.resolver;version="[5.3.6,5.4.0)", + org.eclipse.jgit.transport.sshd;version="[5.3.6,5.4.0)", + org.eclipse.jgit.treewalk;version="[5.3.6,5.4.0)", + org.eclipse.jgit.treewalk.filter;version="[5.3.6,5.4.0)", + org.eclipse.jgit.util;version="[5.3.6,5.4.0)", + org.eclipse.jgit.util.io;version="[5.3.6,5.4.0)", org.kohsuke.args4j;version="[2.33.0,3.0.0)", org.kohsuke.args4j.spi;version="[2.33.0,3.0.0)" -Export-Package: org.eclipse.jgit.console;version="5.2.3"; +Export-Package: org.eclipse.jgit.console;version="5.3.6"; uses:="org.eclipse.jgit.transport, org.eclipse.jgit.util", - org.eclipse.jgit.pgm;version="5.2.3"; + org.eclipse.jgit.pgm;version="5.3.6"; uses:="org.eclipse.jgit.revwalk, org.eclipse.jgit.treewalk.filter, org.eclipse.jgit.pgm.opt, @@ -82,11 +82,11 @@ Export-Package: org.eclipse.jgit.console;version="5.2.3"; org.eclipse.jgit.treewalk, javax.swing, org.eclipse.jgit.transport", - org.eclipse.jgit.pgm.debug;version="5.2.3"; + org.eclipse.jgit.pgm.debug;version="5.3.6"; uses:="org.eclipse.jgit.util.io, org.eclipse.jgit.pgm", - org.eclipse.jgit.pgm.internal;version="5.2.3";x-friends:="org.eclipse.jgit.pgm.test,org.eclipse.jgit.test", - org.eclipse.jgit.pgm.opt;version="5.2.3"; + org.eclipse.jgit.pgm.internal;version="5.3.6";x-friends:="org.eclipse.jgit.pgm.test,org.eclipse.jgit.test", + org.eclipse.jgit.pgm.opt;version="5.3.6"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.revwalk, org.kohsuke.args4j.spi, diff --git a/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF index 9831e1347e..858111e575 100644 --- a/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF @@ -3,5 +3,5 @@ Bundle-ManifestVersion: 2 Bundle-Name: org.eclipse.jgit.pgm - Sources Bundle-SymbolicName: org.eclipse.jgit.pgm.source Bundle-Vendor: Eclipse.org - JGit -Bundle-Version: 5.2.3.qualifier -Eclipse-SourceBundle: org.eclipse.jgit.pgm;version="5.2.3.qualifier";roots="." +Bundle-Version: 5.3.6.qualifier +Eclipse-SourceBundle: org.eclipse.jgit.pgm;version="5.3.6.qualifier";roots="." diff --git a/org.eclipse.jgit.pgm/jgit.sh b/org.eclipse.jgit.pgm/jgit.sh index 826714751c..e263782738 100644 --- a/org.eclipse.jgit.pgm/jgit.sh +++ b/org.eclipse.jgit.pgm/jgit.sh @@ -110,9 +110,9 @@ then LESS=${LESS:-FSRX} export LESS - "$java" $java_args org.eclipse.jgit.pgm.Main "$@" | $use_pager + "$java" $java_args org.springframework.boot.loader.JarLauncher "$@" | $use_pager exit else - exec "$java" $java_args org.eclipse.jgit.pgm.Main "$@" + exec "$java" $java_args org.springframework.boot.loader.JarLauncher "$@" exit 1 fi diff --git a/org.eclipse.jgit.pgm/pom.xml b/org.eclipse.jgit.pgm/pom.xml index 81ef1b3f70..70e3d6988e 100644 --- a/org.eclipse.jgit.pgm/pom.xml +++ b/org.eclipse.jgit.pgm/pom.xml @@ -50,7 +50,7 @@ <parent> <groupId>org.eclipse.jgit</groupId> <artifactId>org.eclipse.jgit-parent</artifactId> - <version>5.2.3-SNAPSHOT</version> + <version>5.3.6-SNAPSHOT</version> </parent> <artifactId>org.eclipse.jgit.pgm</artifactId> @@ -172,40 +172,19 @@ </plugin> <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> - <phase>package</phase> <goals> - <goal>shade</goal> + <goal>repackage</goal> </goals> <configuration> <finalName>jgit-cli</finalName> - <createDependencyReducedPom>false</createDependencyReducedPom> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> - <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> - <manifestEntries> - <Main-Class>org.eclipse.jgit.pgm.Main</Main-Class> - <Implementation-Title>JGit Command Line Interface</Implementation-Title> - </manifestEntries> - </transformer> - </transformers> - <filters> - <!-- exclude the signing data for individual jars, ueberjar will be signed again --> - <filter> - <artifact>*:*</artifact> - <excludes> - <exclude>META-INF/*.SF</exclude> - <exclude>META-INF/*.DSA</exclude> - <exclude>META-INF/*.RSA</exclude> - <exclude>OSGI-OPT/**</exclude> - </excludes> - </filter> - </filters> - <shadedArtifactAttached>true</shadedArtifactAttached> - <shadedClassifierName>shaded</shadedClassifierName> <!-- Any name that makes sense --> + <attach>false</attach> + <mainClass>org.eclipse.jgit.pgm.Main</mainClass> + <executable>true</executable> + <embeddedLaunchScript>jgit.sh</embeddedLaunchScript> </configuration> </execution> </executions> @@ -220,11 +199,13 @@ <phase>package</phase> <configuration> <target> - <concat destfile="${basedir}/target/jgit" force="yes" binary="true"> - <fileset file="${basedir}/jgit.sh" /> - <fileset file="${basedir}/target/jgit-cli.jar" /> - </concat> - <chmod file="${basedir}/target/jgit" perm="a+x"/> + <move + file="${basedir}/target/jgit-cli.jar" + force="yes" + tofile="${basedir}/target/jgit" /> + <chmod + file="${basedir}/target/jgit" + perm="a+x" /> </target> </configuration> <goals> 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 bbf9366ce7..aa2608d78e 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 @@ -49,6 +49,7 @@ cleanRequireForce=clean.requireForce defaults to true and neither -n nor -f give clonedEmptyRepository=warning: You appear to have cloned an empty repository. cloningInto=Cloning into ''{0}''... commitLabel=commit +configOnlyListOptionSupported=only the --list option is currently supported configFileNotFound=configuration file {0} not found conflictingUsageOf_git_dir_andArguments=conflicting usage of --git-dir and arguments couldNotCreateBranch=Could not create branch {0}: {1} @@ -129,6 +130,7 @@ metaVar_path=path metaVar_paths=path ... metaVar_pattern=pattern metaVar_port=PORT +metaVar_prefix=PREFIX metaVar_ref=REF metaVar_refs=REFS metaVar_refspec=refspec @@ -171,7 +173,7 @@ notOnAnyBranch=Not currently on any branch. onBranch=On branch {0} onBranchToBeBorn=You are on a branch yet to be born onlyOneMetaVarExpectedIn=Only one {0} expected in {1}. -onlyOneOfIncludeOnlyAllInteractiveCanBeUsed=Only one of --include/--only/--all/--interactive can be used. +onlyOneCommitOptionAllowed=Only one of --include/--only/--all/--interactive can be used. password=Password: pathspecDidNotMatch=error: pathspec ''{0}'' did not match any file(s) known to git. pushTo=To {0} @@ -182,6 +184,7 @@ remoteRefObjectChangedIsNotExpectedOne=remote ref object changed - is not expect remoteSideDoesNotSupportDeletingRefs=remote side does not support deleting refs removing=Removing {0} repaint=Repaint +resetNoMode=no reset mode set s3InvalidBucket=Invalid S3 bucket ''{0}'' serviceNotSupported=Service ''{0}'' not supported skippingObject=skipping {0} {1} @@ -337,7 +340,8 @@ usage_fetchThinPack=fetch thin pack usage_filesToAddContentFrom=Files to add content from usage_fixAThinPackToBeComplete=fix a thin pack to be complete usage_forEachRefOutput=for-each-ref output -usage_forceCheckout=when switching branches, proceed even if the index or the working tree differs from HEAD +usage_forcedSwitchBranch=when switching branches do it forcefully. Succeed even if resetting an existing branch would cause commits to become unreachable +usage_forceCheckout=when checking out a commit succeed even if the working tree or the index is dirty. Overwrite the working tree or index in such cases usage_forceClean=required to delete files or directories usage_forceCreateBranchEvenExists=force create branch even exists usage_forcedFetch=force ref update fetch option diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java index 08a9f48c04..9ecbbf1375 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java @@ -48,6 +48,7 @@ import java.util.List; import org.eclipse.jgit.api.AddCommand; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -69,6 +70,8 @@ class Add extends TextBuiltin { for (String p : filepatterns) addCmd.addFilepattern(p); addCmd.call(); + } catch (GitAPIException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java index 4721b3a0fd..cb63a9a069 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java @@ -96,11 +96,11 @@ class Archive extends TextBuiltin { if (output != null) cmd.setFilename(output); cmd.call(); - } catch (GitAPIException e) { - throw die(e.getMessage()); - } + } catch (GitAPIException e) { + throw die(e.getMessage(), e); + } } catch (FileNotFoundException e) { - throw die(e.getMessage()); + throw die(e.getMessage(), e); } finally { if (output != null && stream != null) stream.close(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java index 13a38dddf4..3858b3dd0e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java @@ -65,6 +65,7 @@ import org.eclipse.jgit.blame.BlameResult; import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.dircache.DirCache; +import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.PersonIdent; @@ -122,8 +123,6 @@ class Blame extends TextBuiltin { @Argument(index = 1, required = false, metaVar = "metaVar_file") private String file; - private ObjectReader reader; - private final Map<RevCommit, String> abbreviatedCommits = new HashMap<>(); private SimpleDateFormat dateFmt; @@ -136,29 +135,34 @@ class Blame extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { if (file == null) { - if (revision == null) + if (revision == null) { throw die(CLIText.get().fileIsRequired); + } file = revision; revision = null; } boolean autoAbbrev = abbrev == 0; - if (abbrev == 0) + if (abbrev == 0) { abbrev = db.getConfig().getInt("core", "abbrev", 7); //$NON-NLS-1$ //$NON-NLS-2$ - if (!showBlankBoundary) + } + if (!showBlankBoundary) { root = db.getConfig().getBoolean("blame", "blankboundary", false); //$NON-NLS-1$ //$NON-NLS-2$ - if (!root) + } + if (!root) { root = db.getConfig().getBoolean("blame", "showroot", false); //$NON-NLS-1$ //$NON-NLS-2$ + } - if (showRawTimestamp) + if (showRawTimestamp) { dateFmt = new SimpleDateFormat("ZZZZ"); //$NON-NLS-1$ - else + } else { dateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ"); //$NON-NLS-1$ + } - reader = db.newObjectReader(); - try (BlameGenerator generator = new BlameGenerator(db, file)) { + try (ObjectReader reader = db.newObjectReader(); + BlameGenerator generator = new BlameGenerator(db, file)) { RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$ generator.setTextComparator(comparator); @@ -166,10 +170,11 @@ class Blame extends TextBuiltin { RevCommit rangeStart = null; List<RevCommit> rangeEnd = new ArrayList<>(2); for (RevCommit c : reverseRange) { - if (c.has(RevFlag.UNINTERESTING)) + if (c.has(RevFlag.UNINTERESTING)) { rangeStart = c; - else + } else { rangeEnd.add(c); + } } generator.reverse(rangeStart, rangeEnd); } else if (revision != null) { @@ -179,20 +184,23 @@ class Blame extends TextBuiltin { if (!db.isBare()) { DirCache dc = db.readDirCache(); int entry = dc.findEntry(file); - if (0 <= entry) + if (0 <= entry) { generator.push(null, dc.getEntry(entry).getObjectId()); + } File inTree = new File(db.getWorkTree(), file); - if (db.getFS().isFile(inTree)) + if (db.getFS().isFile(inTree)) { generator.push(null, new RawText(inTree)); + } } } blame = BlameResult.create(generator); begin = 0; end = blame.getResultContents().size(); - if (rangeString != null) + if (rangeString != null) { parseLineRangeOption(); + } blame.computeRange(begin, end); int authorWidth = 8; @@ -203,14 +211,16 @@ class Blame extends TextBuiltin { RevCommit c = blame.getSourceCommit(line); if (c != null && !c.has(scanned)) { c.add(scanned); - if (autoAbbrev) - abbrev = Math.max(abbrev, uniqueAbbrevLen(c)); + if (autoAbbrev) { + abbrev = Math.max(abbrev, uniqueAbbrevLen(reader, c)); + } authorWidth = Math.max(authorWidth, author(line).length()); dateWidth = Math.max(dateWidth, date(line).length()); pathWidth = Math.max(pathWidth, path(line).length()); } - while (line + 1 < end && blame.getSourceCommit(line + 1) == c) + while (line + 1 < end && blame.getSourceCommit(line + 1) == c) { line++; + } maxSourceLine = Math.max(maxSourceLine, blame.getSourceLine(line)); } @@ -224,7 +234,7 @@ class Blame extends TextBuiltin { for (int line = begin; line < end;) { RevCommit c = blame.getSourceCommit(line); - String commit = abbreviate(c); + String commit = abbreviate(reader, c); String author = null; String date = null; if (!noAuthor) { @@ -233,12 +243,15 @@ class Blame extends TextBuiltin { } do { outw.print(commit); - if (showSourcePath) + if (showSourcePath) { outw.format(pathFmt, path(line)); - if (showSourceLine) + } + if (showSourceLine) { outw.format(numFmt, valueOf(blame.getSourceLine(line) + 1)); - if (!noAuthor) + } + if (!noAuthor) { outw.format(authorFmt, author, date); + } outw.format(lineFmt, valueOf(line + 1)); outw.flush(); blame.getResultContents().writeLine(outs, line); @@ -246,12 +259,13 @@ class Blame extends TextBuiltin { outw.print('\n'); } while (++line < end && blame.getSourceCommit(line) == c); } - } finally { - reader.close(); + } catch (NoWorkTreeException | IOException e) { + throw die(e.getMessage(), e); } } - private int uniqueAbbrevLen(RevCommit commit) throws IOException { + private int uniqueAbbrevLen(ObjectReader reader, RevCommit commit) + throws IOException { return reader.abbreviate(commit, abbrev).length(); } @@ -345,7 +359,8 @@ class Blame extends TextBuiltin { dateFmt.format(author.getWhen())); } - private String abbreviate(RevCommit commit) throws IOException { + private String abbreviate(ObjectReader reader, RevCommit commit) + throws IOException { String r = abbreviatedCommits.get(commit); if (r != null) return r; diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java index a88354deba..bac697f78e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java @@ -54,6 +54,7 @@ import java.util.Map.Entry; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.ListBranchCommand; import org.eclipse.jgit.api.ListBranchCommand.ListMode; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; @@ -182,15 +183,17 @@ class Branch extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { - if (delete != null || deleteForce != null) { - if (delete != null) { - delete(delete, false); - } - if (deleteForce != null) { - delete(deleteForce, true); + protected void run() { + try { + if (delete != null || deleteForce != null) { + if (delete != null) { + delete(delete, false); + } + if (deleteForce != null) { + delete(deleteForce, true); + } + return; } - } else { if (rename) { String src, dst; if (otherBranch == null) { @@ -204,22 +207,27 @@ class Branch extends TextBuiltin { } else { src = branch; final Ref old = db.findRef(src); - if (old == null) + if (old == null) { throw die(MessageFormat.format(CLIText.get().doesNotExist, src)); - if (!old.getName().startsWith(Constants.R_HEADS)) + } + if (!old.getName().startsWith(Constants.R_HEADS)) { throw die(MessageFormat.format(CLIText.get().notABranch, src)); + } src = old.getName(); dst = otherBranch; } - if (!dst.startsWith(Constants.R_HEADS)) + if (!dst.startsWith(Constants.R_HEADS)) { dst = Constants.R_HEADS + dst; - if (!Repository.isValidRefName(dst)) + } + if (!Repository.isValidRefName(dst)) { throw die(MessageFormat.format(CLIText.get().notAValidRefName, dst)); + } RefRename r = db.renameRef(src, dst); - if (r.rename() != Result.RENAMED) + if (r.rename() != Result.RENAMED) { throw die(MessageFormat.format(CLIText.get().cannotBeRenamed, src)); + } } else if (createForce || branch != null) { String newHead = branch; @@ -264,10 +272,12 @@ class Branch extends TextBuiltin { } list(); } + } catch (IOException | GitAPIException e) { + throw die(e.getMessage(), e); } } - private void list() throws Exception { + private void list() throws IOException, GitAPIException { Ref head = db.exactRef(Constants.HEAD); // This can happen if HEAD is stillborn if (head != null) { @@ -316,7 +326,7 @@ class Branch extends TextBuiltin { } private void printHead(final ObjectReader reader, final String ref, - final boolean isCurrent, final Ref refObj) throws Exception { + final boolean isCurrent, final Ref refObj) throws IOException { outw.print(isCurrent ? '*' : ' '); outw.print(' '); outw.print(ref); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java index 6ff39fab04..7e1737f872 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java @@ -69,8 +69,11 @@ class Checkout extends TextBuiltin { @Option(name = "-b", usage = "usage_createBranchAndCheckout") private boolean createBranch = false; + @Option(name = "-B", usage = "usage_forcedSwitchBranch") + private boolean forceSwitchBranch = false; + @Option(name = "--force", aliases = { "-f" }, usage = "usage_forceCheckout") - private boolean force = false; + private boolean forced = false; @Option(name = "--orphan", usage = "usage_orphan") private boolean orphan = false; @@ -103,7 +106,8 @@ class Checkout extends TextBuiltin { } else { command.setCreateBranch(createBranch); command.setName(name); - command.setForce(force); + command.setForceRefUpdate(forceSwitchBranch); + command.setForced(forced); command.setOrphan(orphan); } try { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clean.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clean.java index 6ae078c953..db9e959259 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clean.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clean.java @@ -43,10 +43,13 @@ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.text.MessageFormat; import java.util.Set; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.pgm.internal.CLIText; import org.kohsuke.args4j.Option; @@ -64,7 +67,7 @@ class Clean extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { boolean requireForce = git.getRepository().getConfig() .getBoolean("clean", "requireForce", true); //$NON-NLS-1$ //$NON-NLS-2$ @@ -82,6 +85,8 @@ class Clean extends TextBuiltin { outw.println(MessageFormat.format(CLIText.get().removing, removedFile)); } + } catch (NoWorkTreeException | GitAPIException | IOException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 393c607a2b..fe2462012b 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -110,7 +110,7 @@ class Clone extends AbstractFetchCommand implements CloneCommand.Callback { Constants.OS_USER_DIR), localName); } catch (IllegalArgumentException e) { throw die(MessageFormat.format( - CLIText.get().cannotGuessLocalNameFrom, sourceUri)); + CLIText.get().cannotGuessLocalNameFrom, sourceUri), e); } } else localNameF = new File(localName); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java index 2e67c02cb0..b0713f782c 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java @@ -37,18 +37,18 @@ */ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.eclipse.jgit.api.CommitCommand; import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.NoHeadException; -import org.eclipse.jgit.api.errors.NoMessageException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.pgm.internal.CLIText; +import org.eclipse.jgit.pgm.opt.GpgSignHandler; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.util.RawParseUtils; import org.kohsuke.args4j.Argument; @@ -74,26 +74,46 @@ class Commit extends TextBuiltin { @Option(name = "--amend", usage = "usage_CommitAmend") private boolean amend; + @Option(name = "--gpg-sign", aliases = { "-S" }, forbids = { + "--no-gpg-sign" }, handler = GpgSignHandler.class) + private String gpgSigningKey; + + @Option(name = "--no-gpg-sign", forbids = { "--gpg-sign" }) + private boolean noGpgSign; + @Argument(metaVar = "metaVar_commitPaths", usage = "usage_CommitPaths") private List<String> paths = new ArrayList<>(); /** {@inheritDoc} */ @Override - protected void run() throws NoHeadException, NoMessageException, - ConcurrentRefUpdateException, JGitInternalException, Exception { + protected void run() { try (Git git = new Git(db)) { CommitCommand commitCmd = git.commit(); - if (author != null) + if (author != null) { commitCmd.setAuthor(RawParseUtils.parsePersonIdent(author)); - if (message != null) + } + if (message != null) { commitCmd.setMessage(message); - if (only && paths.isEmpty()) + } + if (noGpgSign) { + commitCmd.setSign(Boolean.FALSE); + } else if (gpgSigningKey != null) { + commitCmd.setSign(Boolean.TRUE); + if (!gpgSigningKey.equals(GpgSignHandler.DEFAULT)) { + commitCmd.setSigningKey(gpgSigningKey); + } + } + if (only && paths.isEmpty()) { throw die(CLIText.get().pathsRequired); - if (only && all) - throw die(CLIText.get().onlyOneOfIncludeOnlyAllInteractiveCanBeUsed); - if (!paths.isEmpty()) - for (String p : paths) + } + if (only && all) { + throw die(CLIText.get().onlyOneCommitOptionAllowed); + } + if (!paths.isEmpty()) { + for (String p : paths) { commitCmd.setOnly(p); + } + } commitCmd.setAmend(amend); commitCmd.setAll(all); Ref head = db.exactRef(Constants.HEAD); @@ -103,20 +123,24 @@ class Commit extends TextBuiltin { RevCommit commit; try { commit = commitCmd.call(); - } catch (JGitInternalException e) { - throw die(e.getMessage()); + } catch (JGitInternalException | GitAPIException e) { + throw die(e.getMessage(), e); } String branchName; - if (!head.isSymbolic()) + if (!head.isSymbolic()) { branchName = CLIText.get().branchDetachedHEAD; - else { + } else { branchName = head.getTarget().getName(); - if (branchName.startsWith(Constants.R_HEADS)) - branchName = branchName.substring(Constants.R_HEADS.length()); + if (branchName.startsWith(Constants.R_HEADS)) { + branchName = branchName + .substring(Constants.R_HEADS.length()); + } } - outw.println("[" + branchName + " " + commit.name() + "] " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + outw.println('[' + branchName + ' ' + commit.name() + "] " //$NON-NLS-1$ + commit.getShortMessage()); + } catch (IOException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java index f762c0d052..979c6fa945 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Config.java @@ -42,9 +42,9 @@ import java.io.IOException; import java.util.Set; import org.eclipse.jgit.errors.ConfigInvalidException; -import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.pgm.internal.CLIText; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.StringUtils; @@ -70,12 +70,15 @@ class Config extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { - if (list) + protected void run() { + if (!list) { + throw die(CLIText.get().configOnlyListOptionSupported); + } + try { list(); - else - throw new NotSupportedException( - "only --list option is currently supported"); //$NON-NLS-1$ + } catch (IOException | ConfigInvalidException e) { + throw die(e.getMessage(), e); + } } private void list() throws IOException, ConfigInvalidException { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java index f91474859d..d89fee6239 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java @@ -42,12 +42,15 @@ */ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.eclipse.jgit.api.DescribeCommand; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.RefNotFoundException; +import org.eclipse.jgit.errors.InvalidPatternException; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.pgm.internal.CLIText; import org.kohsuke.args4j.Argument; @@ -67,11 +70,12 @@ class Describe extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { DescribeCommand cmd = git.describe(); - if (tree != null) + if (tree != null) { cmd.setTarget(tree); + } cmd.setLong(longDesc); cmd.setMatch(patterns.toArray(new String[0])); String result = null; @@ -80,10 +84,13 @@ class Describe extends TextBuiltin { } catch (RefNotFoundException e) { throw die(CLIText.get().noNamesFound, e); } - if (result == null) + if (result == null) { throw die(CLIText.get().noNamesFound); + } outw.println(result); + } catch (IOException | InvalidPatternException | GitAPIException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java index 97e3df38d6..7747dc7dd7 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java @@ -62,6 +62,7 @@ import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.diff.RenameDetector; import org.eclipse.jgit.dircache.DirCacheIterator; +import org.eclipse.jgit.errors.RevisionSyntaxException; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.Repository; @@ -150,12 +151,12 @@ class Diff extends TextBuiltin { diffFmt.setAbbreviationLength(OBJECT_ID_STRING_LENGTH); } - @Option(name = "--src-prefix", usage = "usage_srcPrefix") + @Option(name = "--src-prefix", metaVar = "metaVar_prefix", usage = "usage_srcPrefix") void sourcePrefix(String path) { diffFmt.setOldPrefix(path); } - @Option(name = "--dst-prefix", usage = "usage_dstPrefix") + @Option(name = "--dst-prefix", metaVar = "metaVar_prefix", usage = "usage_dstPrefix") void dstPrefix(String path) { diffFmt.setNewPrefix(path); } @@ -177,14 +178,15 @@ class Diff extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { diffFmt.setRepository(db); try { if (cached) { if (oldTree == null) { ObjectId head = db.resolve(HEAD + "^{tree}"); //$NON-NLS-1$ - if (head == null) + if (head == null) { die(MessageFormat.format(CLIText.get().notATree, HEAD)); + } CanonicalTreeParser p = new CanonicalTreeParser(); try (ObjectReader reader = db.newObjectReader()) { p.reset(reader, head); @@ -195,15 +197,17 @@ class Diff extends TextBuiltin { } else if (oldTree == null) { oldTree = new DirCacheIterator(db.readDirCache()); newTree = new FileTreeIterator(db); - } else if (newTree == null) + } else if (newTree == null) { newTree = new FileTreeIterator(db); + } TextProgressMonitor pm = new TextProgressMonitor(errw); pm.setDelayStart(2, TimeUnit.SECONDS); diffFmt.setProgressMonitor(pm); diffFmt.setPathFilter(pathFilter); - if (detectRenames != null) + if (detectRenames != null) { diffFmt.setDetectRenames(detectRenames.booleanValue()); + } if (renameLimit != null && diffFmt.isDetectRenames()) { RenameDetector rd = diffFmt.getRenameDetector(); rd.setRenameLimit(renameLimit.intValue()); @@ -212,11 +216,12 @@ class Diff extends TextBuiltin { if (showNameAndStatusOnly) { nameStatus(outw, diffFmt.scan(oldTree, newTree)); outw.flush(); - } else { diffFmt.format(oldTree, newTree); diffFmt.flush(); } + } catch (RevisionSyntaxException | IOException e) { + throw die(e.getMessage(), e); } finally { diffFmt.close(); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTree.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTree.java index 42aabc2f49..371395ba3f 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTree.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTree.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -74,7 +75,7 @@ class DiffTree extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (TreeWalk walk = new TreeWalk(db)) { walk.setRecursive(recursive); for (AbstractTreeIterator i : trees) @@ -83,13 +84,15 @@ class DiffTree extends TextBuiltin { final int nTree = walk.getTreeCount(); while (walk.next()) { - for (int i = 1; i < nTree; i++) + for (int i = 1; i < nTree; i++) { outw.print(':'); + } for (int i = 0; i < nTree; i++) { final FileMode m = walk.getFileMode(i); final String s = m.toString(); - for (int pad = 6 - s.length(); pad > 0; pad--) + for (int pad = 6 - s.length(); pad > 0; pad--) { outw.print('0'); + } outw.print(s); outw.print(' '); } @@ -103,12 +106,13 @@ class DiffTree extends TextBuiltin { if (nTree == 2) { final int m0 = walk.getRawMode(0); final int m1 = walk.getRawMode(1); - if (m0 == 0 && m1 != 0) + if (m0 == 0 && m1 != 0) { chg = 'A'; - else if (m0 != 0 && m1 == 0) + } else if (m0 != 0 && m1 == 0) { chg = 'D'; - else if (m0 != m1 && walk.idEqual(0, 1)) + } else if (m0 != m1 && walk.idEqual(0, 1)) { chg = 'T'; + } } outw.print(chg); @@ -116,6 +120,8 @@ class DiffTree extends TextBuiltin { outw.print(walk.getPathString()); outw.println(); } + } catch (IOException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java index 61fd521b80..da3c498796 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java @@ -51,6 +51,7 @@ import java.util.List; import org.eclipse.jgit.api.FetchCommand; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.SubmoduleConfig.FetchRecurseSubmodulesMode; import org.eclipse.jgit.lib.TextProgressMonitor; @@ -136,27 +137,33 @@ class Fetch extends AbstractFetchCommand implements FetchCommand.Callback { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { FetchCommand fetch = git.fetch(); - if (fsck != null) + if (fsck != null) { fetch.setCheckFetchedObjects(fsck.booleanValue()); - if (prune != null) + } + if (prune != null) { fetch.setRemoveDeletedRefs(prune.booleanValue()); - if (toget != null) + } + if (toget != null) { fetch.setRefSpecs(toget); + } if (tags != null) { fetch.setTagOpt(tags.booleanValue() ? TagOpt.FETCH_TAGS : TagOpt.NO_TAGS); } - if (0 <= timeout) + if (0 <= timeout) { fetch.setTimeout(timeout); + } fetch.setDryRun(dryRun); fetch.setRemote(remote); - if (thin != null) + if (thin != null) { fetch.setThin(thin.booleanValue()); - if (quiet == null || !quiet.booleanValue()) + } + if (quiet == null || !quiet.booleanValue()) { fetch.setProgressMonitor(new TextProgressMonitor(errw)); + } fetch.setRecurseSubmodules(recurseSubmodules).setCallback(this); if (force != null) { fetch.setForceUpdate(force.booleanValue()); @@ -164,10 +171,12 @@ class Fetch extends AbstractFetchCommand implements FetchCommand.Callback { FetchResult result = fetch.call(); if (result.getTrackingRefUpdates().isEmpty() - && result.submoduleResults().isEmpty()) + && result.submoduleResults().isEmpty()) { return; - + } showFetchResult(result); + } catch (GitAPIException | IOException e) { + throw die(e.getMessage(), e); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Gc.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Gc.java index 56172f57c3..e65f0ec844 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Gc.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Gc.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.pgm; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.TextProgressMonitor; import org.kohsuke.args4j.Option; @@ -60,11 +61,15 @@ class Gc extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { Git git = Git.wrap(db); - git.gc().setAggressive(aggressive) - .setPreserveOldPacks(preserveOldPacks) - .setPrunePreserved(prunePreserved) - .setProgressMonitor(new TextProgressMonitor(errw)).call(); + try { + git.gc().setAggressive(aggressive) + .setPreserveOldPacks(preserveOldPacks) + .setPrunePreserved(prunePreserved) + .setProgressMonitor(new TextProgressMonitor(errw)).call(); + } catch (GitAPIException e) { + throw die(e.getMessage(), e); + } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java index 26276718df..394083c851 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.pgm; import java.io.BufferedInputStream; +import java.io.IOException; import org.eclipse.jgit.internal.storage.file.ObjectDirectoryPackParser; import org.eclipse.jgit.lib.ObjectInserter; @@ -62,7 +63,7 @@ class IndexPack extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { BufferedInputStream in = new BufferedInputStream(ins); try (ObjectInserter inserter = db.newObjectInserter()) { PackParser p = inserter.newPackParser(in); @@ -73,6 +74,8 @@ class IndexPack extends TextBuiltin { } p.parse(new TextProgressMonitor(errw)); inserter.flush(); + } catch (IOException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java index f880fc2076..d24733dee8 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java @@ -49,10 +49,12 @@ package org.eclipse.jgit.pgm; import java.io.File; +import java.io.IOException; import java.text.MessageFormat; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.InitCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.pgm.internal.CLIText; import org.kohsuke.args4j.Argument; @@ -74,7 +76,7 @@ class Init extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { InitCommand command = Git.init(); command.setBare(bare); if (gitdir != null) { @@ -83,9 +85,14 @@ class Init extends TextBuiltin { if (directory != null) { command.setDirectory(new File(directory)); } - Repository repository = command.call().getRepository(); - outw.println(MessageFormat.format( - CLIText.get().initializedEmptyGitRepositoryIn, repository - .getDirectory().getAbsolutePath())); + Repository repository; + try { + repository = command.call().getRepository(); + outw.println(MessageFormat.format( + CLIText.get().initializedEmptyGitRepositoryIn, + repository.getDirectory().getAbsolutePath())); + } catch (GitAPIException | IOException e) { + throw die(e.getMessage(), e); + } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java index ad92a78f69..05b7980c24 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java @@ -193,12 +193,13 @@ class Log extends RevWalkTextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { diffFmt.setRepository(db); try { diffFmt.setPathFilter(pathFilter); - if (detectRenames != null) + if (detectRenames != null) { diffFmt.setDetectRenames(detectRenames.booleanValue()); + } if (renameLimit != null && diffFmt.isDetectRenames()) { RenameDetector rd = diffFmt.getRenameDetector(); rd.setRenameLimit(renameLimit.intValue()); @@ -220,11 +221,13 @@ class Log extends RevWalkTextBuiltin { } } - if (decorate) + if (decorate) { allRefsByPeeledObjectId = getRepository() .getAllRefsByPeeledObjectId(); - + } super.run(); + } catch (Exception e) { + throw die(e.getMessage(), e); } finally { diffFmt.close(); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsFiles.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsFiles.java index dc13000d63..ef25844973 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsFiles.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsFiles.java @@ -48,11 +48,13 @@ import static org.eclipse.jgit.lib.FileMode.GITLINK; import static org.eclipse.jgit.lib.FileMode.REGULAR_FILE; import static org.eclipse.jgit.lib.FileMode.SYMLINK; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.eclipse.jgit.dircache.DirCacheIterator; +import org.eclipse.jgit.errors.RevisionSyntaxException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; @@ -72,7 +74,7 @@ class LsFiles extends TextBuiltin { private List<String> paths = new ArrayList<>(); @Override - protected void run() throws Exception { + protected void run() { try (RevWalk rw = new RevWalk(db); TreeWalk tw = new TreeWalk(db)) { final ObjectId head = db.resolve(Constants.HEAD); @@ -96,6 +98,8 @@ class LsFiles extends TextBuiltin { QuotedString.GIT_PATH.quote(tw.getPathString())); } } + } catch (RevisionSyntaxException | IOException e) { + throw die(e.getMessage(), e); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java index 2711c15729..1c2564dd7c 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java @@ -51,6 +51,7 @@ import java.util.TreeSet; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.LsRemoteCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Ref; import org.kohsuke.args4j.Argument; @@ -72,7 +73,7 @@ class LsRemote extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { LsRemoteCommand command = Git.lsRemoteRepository().setRemote(remote) .setTimeout(timeout).setHeads(heads).setTags(tags); TreeSet<Ref> refs = new TreeSet<>(new Comparator<Ref>() { @@ -82,11 +83,16 @@ class LsRemote extends TextBuiltin { return r1.getName().compareTo(r2.getName()); } }); - refs.addAll(command.call()); - for (Ref r : refs) { - show(r.getObjectId(), r.getName()); - if (r.getPeeledObjectId() != null) - show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$ + try { + refs.addAll(command.call()); + for (Ref r : refs) { + show(r.getObjectId(), r.getName()); + if (r.getPeeledObjectId() != null) { + show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$ + } + } + } catch (GitAPIException | IOException e) { + throw die(e.getMessage(), e); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java index 01fa7eeb81..2a2bb7cc91 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -72,18 +73,20 @@ class LsTree extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (TreeWalk walk = new TreeWalk(db)) { walk.reset(); // drop the first empty tree, which we do not need here - if (paths.size() > 0) + if (paths.size() > 0) { walk.setFilter(PathFilterGroup.createFromStrings(paths)); + } walk.setRecursive(recursive); walk.addTree(tree); while (walk.next()) { final FileMode mode = walk.getFileMode(0); - if (mode == FileMode.TREE) + if (mode == FileMode.TREE) { outw.print('0'); + } outw.print(mode); outw.print(' '); outw.print(Constants.typeString(mode.getObjectType())); @@ -95,6 +98,8 @@ class LsTree extends TextBuiltin { outw.print(QuotedString.GIT_PATH.quote(walk.getPathString())); outw.println(); } + } catch (IOException e) { + throw die(e.getMessage(), e); } } } 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 de059e9416..0b362a42f3 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 @@ -52,6 +52,7 @@ import org.eclipse.jgit.api.MergeCommand; import org.eclipse.jgit.api.MergeCommand.FastForwardMode; import org.eclipse.jgit.api.MergeResult; import org.eclipse.jgit.api.errors.CheckoutConflictException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -103,110 +104,124 @@ class Merge extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { - if (squash && ff == FastForwardMode.NO_FF) + protected void run() { + if (squash && ff == FastForwardMode.NO_FF) { throw die(CLIText.get().cannotCombineSquashWithNoff); + } // determine the merge strategy if (strategyName != null) { mergeStrategy = MergeStrategy.get(strategyName); - if (mergeStrategy == null) + if (mergeStrategy == null) { throw die(MessageFormat.format( CLIText.get().unknownMergeStrategy, strategyName)); + } } - // determine the other revision we want to merge with HEAD - final Ref srcRef = db.findRef(ref); - final ObjectId src = db.resolve(ref + "^{commit}"); //$NON-NLS-1$ - if (src == null) - throw die(MessageFormat.format( - CLIText.get().refDoesNotExistOrNoCommit, ref)); - - Ref oldHead = getOldHead(); - MergeResult result; - try (Git git = new Git(db)) { - MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy) - .setSquash(squash).setFastForward(ff).setCommit(!noCommit); - if (srcRef != null) - mergeCmd.include(srcRef); - else - mergeCmd.include(src); - - if (message != null) - mergeCmd.setMessage(message); - - try { - result = mergeCmd.call(); - } catch (CheckoutConflictException e) { - result = new MergeResult(e.getConflictingPaths()); // CHECKOUT_CONFLICT + try { + // determine the other revision we want to merge with HEAD + final Ref srcRef = db.findRef(ref); + final ObjectId src = db.resolve(ref + "^{commit}"); //$NON-NLS-1$ + if (src == null) { + throw die(MessageFormat + .format(CLIText.get().refDoesNotExistOrNoCommit, ref)); } - } - switch (result.getMergeStatus()) { - case ALREADY_UP_TO_DATE: - if (squash) - outw.print(CLIText.get().nothingToSquash); - outw.println(CLIText.get().alreadyUpToDate); - break; - case FAST_FORWARD: - ObjectId oldHeadId = oldHead.getObjectId(); - if (oldHeadId != null) { - String oldId = oldHeadId.abbreviate(7).name(); - String newId = result.getNewHead().abbreviate(7).name(); - outw.println(MessageFormat.format(CLIText.get().updating, oldId, - newId)); + Ref oldHead = getOldHead(); + MergeResult result; + try (Git git = new Git(db)) { + MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy) + .setSquash(squash).setFastForward(ff) + .setCommit(!noCommit); + if (srcRef != null) { + mergeCmd.include(srcRef); + } else { + mergeCmd.include(src); + } + + if (message != null) { + mergeCmd.setMessage(message); + } + + try { + result = mergeCmd.call(); + } catch (CheckoutConflictException e) { + result = new MergeResult(e.getConflictingPaths()); // CHECKOUT_CONFLICT + } } - outw.println(result.getMergeStatus().toString()); - break; - case CHECKOUT_CONFLICT: - outw.println(CLIText.get().mergeCheckoutConflict); - for (String collidingPath : result.getCheckoutConflicts()) - outw.println("\t" + collidingPath); //$NON-NLS-1$ - outw.println(CLIText.get().mergeCheckoutFailed); - break; - case CONFLICTING: - for (String collidingPath : result.getConflicts().keySet()) - outw.println(MessageFormat.format(CLIText.get().mergeConflict, - collidingPath)); - outw.println(CLIText.get().mergeFailed); - break; - case FAILED: - for (Map.Entry<String, MergeFailureReason> entry : result - .getFailingPaths().entrySet()) - switch (entry.getValue()) { - case DIRTY_WORKTREE: - case DIRTY_INDEX: - outw.println(CLIText.get().dontOverwriteLocalChanges); - outw.println(" " + entry.getKey()); //$NON-NLS-1$ - break; - case COULD_NOT_DELETE: - outw.println(CLIText.get().cannotDeleteFile); - outw.println(" " + entry.getKey()); //$NON-NLS-1$ - break; + + switch (result.getMergeStatus()) { + case ALREADY_UP_TO_DATE: + if (squash) { + outw.print(CLIText.get().nothingToSquash); + } + outw.println(CLIText.get().alreadyUpToDate); + break; + case FAST_FORWARD: + ObjectId oldHeadId = oldHead.getObjectId(); + if (oldHeadId != null) { + String oldId = oldHeadId.abbreviate(7).name(); + String newId = result.getNewHead().abbreviate(7).name(); + outw.println(MessageFormat.format(CLIText.get().updating, + oldId, newId)); } - break; - case MERGED: - String name; - if (!isMergedInto(oldHead, src)) - name = mergeStrategy.getName(); - else - name = "recursive"; //$NON-NLS-1$ - outw.println(MessageFormat.format(CLIText.get().mergeMadeBy, name)); - break; - case MERGED_NOT_COMMITTED: - outw.println(CLIText.get().mergeWentWellStoppedBeforeCommitting); - break; - case MERGED_SQUASHED: - case FAST_FORWARD_SQUASHED: - case MERGED_SQUASHED_NOT_COMMITTED: - outw.println(CLIText.get().mergedSquashed); - outw.println(CLIText.get().mergeWentWellStoppedBeforeCommitting); - break; - case ABORTED: - throw die(CLIText.get().ffNotPossibleAborting); - case NOT_SUPPORTED: - outw.println(MessageFormat.format( - CLIText.get().unsupportedOperation, result.toString())); + outw.println(result.getMergeStatus().toString()); + break; + case CHECKOUT_CONFLICT: + outw.println(CLIText.get().mergeCheckoutConflict); + for (String collidingPath : result.getCheckoutConflicts()) { + outw.println("\t" + collidingPath); //$NON-NLS-1$ + } + outw.println(CLIText.get().mergeCheckoutFailed); + break; + case CONFLICTING: + for (String collidingPath : result.getConflicts().keySet()) + outw.println(MessageFormat.format( + CLIText.get().mergeConflict, collidingPath)); + outw.println(CLIText.get().mergeFailed); + break; + case FAILED: + for (Map.Entry<String, MergeFailureReason> entry : result + .getFailingPaths().entrySet()) + switch (entry.getValue()) { + case DIRTY_WORKTREE: + case DIRTY_INDEX: + outw.println(CLIText.get().dontOverwriteLocalChanges); + outw.println(" " + entry.getKey()); //$NON-NLS-1$ + break; + case COULD_NOT_DELETE: + outw.println(CLIText.get().cannotDeleteFile); + outw.println(" " + entry.getKey()); //$NON-NLS-1$ + break; + } + break; + case MERGED: + MergeStrategy strategy = isMergedInto(oldHead, src) + ? MergeStrategy.RECURSIVE + : mergeStrategy; + outw.println(MessageFormat.format(CLIText.get().mergeMadeBy, + strategy.getName())); + break; + case MERGED_NOT_COMMITTED: + outw.println( + CLIText.get().mergeWentWellStoppedBeforeCommitting); + break; + case MERGED_SQUASHED: + case FAST_FORWARD_SQUASHED: + case MERGED_SQUASHED_NOT_COMMITTED: + outw.println(CLIText.get().mergedSquashed); + outw.println( + CLIText.get().mergeWentWellStoppedBeforeCommitting); + break; + case ABORTED: + throw die(CLIText.get().ffNotPossibleAborting); + case NOT_SUPPORTED: + outw.println(MessageFormat.format( + CLIText.get().unsupportedOperation, result.toString())); + } + } catch (GitAPIException | IOException e) { + throw die(e.getMessage(), e); } + } private Ref getOldHead() throws IOException { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeBase.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeBase.java index 6842d8ddbf..60b174376b 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeBase.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeBase.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -67,16 +68,22 @@ class MergeBase extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { - for (RevCommit c : commits) - argWalk.markStart(c); - argWalk.setRevFilter(RevFilter.MERGE_BASE); - int max = all ? Integer.MAX_VALUE : 1; - while (max-- > 0) { - final RevCommit b = argWalk.next(); - if (b == null) - break; - outw.println(b.getId().name()); + protected void run() { + try { + for (RevCommit c : commits) { + argWalk.markStart(c); + } + argWalk.setRevFilter(RevFilter.MERGE_BASE); + int max = all ? Integer.MAX_VALUE : 1; + while (max-- > 0) { + final RevCommit b = argWalk.next(); + if (b == null) { + break; + } + outw.println(b.getId().name()); + } + } catch (IOException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java index be8ad374d3..e65e5d16ed 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java @@ -53,6 +53,7 @@ import java.util.List; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.PushCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; @@ -115,7 +116,7 @@ class Push extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { PushCommand push = git.push(); push.setDryRun(dryRun); @@ -123,10 +124,12 @@ class Push extends TextBuiltin { push.setProgressMonitor(new TextProgressMonitor(errw)); push.setReceivePack(receivePack); push.setRefSpecs(refSpecs); - if (all) + if (all) { push.setPushAll(); - if (tags) + } + if (tags) { push.setPushTags(); + } push.setRemote(remote); push.setThin(thin); push.setAtomic(atomic); @@ -140,6 +143,8 @@ class Push extends TextBuiltin { printPushResult(reader, result.getURI(), result); } } + } catch (GitAPIException | IOException e) { + throw die(e.getMessage(), e); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java index f3baafb0b7..b601d80bcd 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.pgm; import java.io.File; +import java.io.IOException; import java.text.MessageFormat; import org.eclipse.jgit.errors.RepositoryNotFoundException; @@ -66,7 +67,7 @@ class ReceivePack extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { final org.eclipse.jgit.transport.ReceivePack rp; try { @@ -75,9 +76,15 @@ class ReceivePack extends TextBuiltin { } catch (RepositoryNotFoundException notFound) { throw die(MessageFormat.format(CLIText.get().notAGitRepository, dstGitdir.getPath())); + } catch (IOException e) { + throw die(e.getMessage(), e); } rp = new org.eclipse.jgit.transport.ReceivePack(db); - rp.receive(ins, outs, errs); + try { + rp.receive(ins, outs, errs); + } catch (IOException e) { + throw die(e.getMessage(), e); + } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java index 6f4fcc2488..410e88fdee 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java @@ -42,10 +42,12 @@ */ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.util.Collection; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.ReflogCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.lib.Repository; @@ -59,7 +61,7 @@ class Reflog extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { ReflogCommand cmd = git.reflog(); if (ref != null) @@ -69,6 +71,8 @@ class Reflog extends TextBuiltin { for (ReflogEntry entry : entries) { outw.println(toString(entry, i++)); } + } catch (GitAPIException | IOException e) { + throw die(e.getMessage(), e); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java index 63eba15abc..58138fa03b 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java @@ -53,6 +53,7 @@ import org.eclipse.jgit.api.RemoteAddCommand; import org.eclipse.jgit.api.RemoteListCommand; import org.eclipse.jgit.api.RemoteRemoveCommand; import org.eclipse.jgit.api.RemoteSetUrlCommand; +import org.eclipse.jgit.api.RemoteSetUrlCommand.UriType; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.pgm.internal.CLIText; import org.eclipse.jgit.pgm.opt.CmdLineParser; @@ -86,7 +87,7 @@ class Remote extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { if (command == null) { RemoteListCommand cmd = git.remoteList(); @@ -99,13 +100,13 @@ class Remote extends TextBuiltin { cmd.call(); } else if ("remove".equals(command) || "rm".equals(command)) { //$NON-NLS-1$ //$NON-NLS-2$ RemoteRemoveCommand cmd = git.remoteRemove(); - cmd.setName(name); + cmd.setRemoteName(name); cmd.call(); } else if ("set-url".equals(command)) { //$NON-NLS-1$ RemoteSetUrlCommand cmd = git.remoteSetUrl(); - cmd.setName(name); - cmd.setUri(new URIish(uri)); - cmd.setPush(push); + cmd.setRemoteName(name); + cmd.setRemoteUri(new URIish(uri)); + cmd.setUriType(push ? UriType.PUSH : UriType.FETCH); cmd.call(); } else if ("update".equals(command)) { //$NON-NLS-1$ // reuse fetch command for basic implementation of remote update @@ -141,6 +142,8 @@ class Remote extends TextBuiltin { throw new JGitInternalException(MessageFormat .format(CLIText.get().unknownSubcommand, command)); } + } catch (Exception e) { + throw die(e.getMessage(), e); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Repo.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Repo.java index f557211fd9..eec562dc05 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Repo.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Repo.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.pgm; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.gitrepo.RepoCommand; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -60,11 +61,15 @@ class Repo extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { - new RepoCommand(db) - .setURI(uri) - .setPath(path) - .setGroups(groups) - .call(); + protected void run() { + try { + new RepoCommand(db) + .setURI(uri) + .setPath(path) + .setGroups(groups) + .call(); + } catch (GitAPIException e) { + throw die(e.getMessage(), e); + } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java index f84c848063..b3e81c6d65 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java @@ -49,6 +49,8 @@ import java.util.List; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.ResetCommand; import org.eclipse.jgit.api.ResetCommand.ResetType; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.pgm.internal.CLIText; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; import org.kohsuke.args4j.spi.RestOfArgumentsHandler; @@ -74,26 +76,33 @@ class Reset extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { ResetCommand command = git.reset(); command.setRef(commit); if (paths.size() > 0) { - for (String path : paths) + for (String path : paths) { command.addPath(path); + } } else { ResetType mode = null; - if (soft) + if (soft) { mode = selectMode(mode, ResetType.SOFT); - if (mixed) + } + if (mixed) { mode = selectMode(mode, ResetType.MIXED); - if (hard) + } + if (hard) { mode = selectMode(mode, ResetType.HARD); - if (mode == null) - throw die("no reset mode set"); //$NON-NLS-1$ + } + if (mode == null) { + throw die(CLIText.get().resetNoMode); + } command.setMode(mode); } command.call(); + } catch (GitAPIException e) { + throw die(e.getMessage(), e); } } 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 ac08cd6ac3..9ff12d8246 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 @@ -45,6 +45,7 @@ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -69,27 +70,31 @@ class RevParse extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { - if (all) { - for (Ref r : db.getRefDatabase().getRefs()) { - ObjectId objectId = r.getObjectId(); - // getRefs skips dangling symrefs, so objectId should never be - // null. - if (objectId == null) { - throw new NullPointerException(); + protected void run() { + try { + if (all) { + for (Ref r : db.getRefDatabase().getRefs()) { + ObjectId objectId = r.getObjectId(); + // getRefs skips dangling symrefs, so objectId should never + // be null. + if (objectId == null) { + throw new NullPointerException(); + } + outw.println(objectId.name()); + } + } else { + if (verify && commits.size() > 1) { + final CmdLineParser clp = new CmdLineParser(this); + throw new CmdLineException(clp, + CLIText.format(CLIText.get().needSingleRevision)); } - outw.println(objectId.name()); - } - } else { - if (verify && commits.size() > 1) { - final CmdLineParser clp = new CmdLineParser(this); - throw new CmdLineException(clp, - CLIText.format(CLIText.get().needSingleRevision)); - } - for (ObjectId o : commits) { - outw.println(o.name()); + for (ObjectId o : commits) { + outw.println(o.name()); + } } + } catch (IOException | CmdLineException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java index f59161039e..4b66462b86 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java @@ -49,6 +49,7 @@ import java.util.List; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.RmCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; import org.kohsuke.args4j.spi.StopOptionHandler; @@ -61,12 +62,15 @@ class Rm extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { RmCommand command = git.rm(); - for (String p : paths) + for (String p : paths) { command.addFilepattern(p); + } command.call(); + } catch (GitAPIException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java index 89a15fe4d8..ff3d003831 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java @@ -59,6 +59,7 @@ import org.eclipse.jgit.diff.RenameDetector; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.errors.RevisionSyntaxException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; @@ -175,22 +176,24 @@ class Show extends TextBuiltin { /** {@inheritDoc} */ @SuppressWarnings("boxing") @Override - protected void run() throws Exception { + protected void run() { diffFmt.setRepository(db); try { diffFmt.setPathFilter(pathFilter); - if (detectRenames != null) + if (detectRenames != null) { diffFmt.setDetectRenames(detectRenames.booleanValue()); + } if (renameLimit != null && diffFmt.isDetectRenames()) { RenameDetector rd = diffFmt.getRenameDetector(); rd.setRenameLimit(renameLimit.intValue()); } ObjectId objectId; - if (objectName == null) + if (objectName == null) { objectId = db.resolve(Constants.HEAD); - else + } else { objectId = db.resolve(objectName); + } try (RevWalk rw = new RevWalk(db)) { RevObject obj = rw.parseAny(objectId); @@ -224,6 +227,8 @@ class Show extends TextBuiltin { obj.getType())); } } + } catch (RevisionSyntaxException | IOException e) { + throw die(e.getMessage(), e); } finally { diffFmt.close(); } @@ -273,7 +278,7 @@ class Show extends TextBuiltin { } } - private void show(RevWalk rw, RevCommit c) throws Exception { + private void show(RevWalk rw, RevCommit c) throws IOException { char[] outbuffer = new char[Constants.OBJECT_ID_LENGTH * 2]; outw.print(CLIText.get().commitLabel); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java index 6318a633ca..b8442c5a50 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java @@ -56,15 +56,20 @@ import org.eclipse.jgit.lib.RefComparator; class ShowRef extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { - for (Ref r : getSortedRefs()) { - show(r.getObjectId(), r.getName()); - if (r.getPeeledObjectId() != null) - show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$ + protected void run() { + try { + for (Ref r : getSortedRefs()) { + show(r.getObjectId(), r.getName()); + if (r.getPeeledObjectId() != null) { + show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$ + } + } + } catch (IOException e) { + throw die(e.getMessage(), e); } } - private Iterable<Ref> getSortedRefs() throws Exception { + private Iterable<Ref> getSortedRefs() throws IOException { List<Ref> all = db.getRefDatabase().getRefs(); // TODO(jrn) check if we can reintroduce fast-path by e.g. implementing // SortedList diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java index fb2fd7e235..dfc8a9436f 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java @@ -54,6 +54,8 @@ import java.util.TreeSet; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.StatusCommand; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.IndexDiff.StageState; import org.eclipse.jgit.lib.Ref; @@ -88,14 +90,18 @@ class Status extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { StatusCommand statusCommand = git.status(); - if (filterPaths != null && filterPaths.size() > 0) - for (String path : filterPaths) + if (filterPaths != null && filterPaths.size() > 0) { + for (String path : filterPaths) { statusCommand.addPath(path); + } + } org.eclipse.jgit.api.Status status = statusCommand.call(); printStatus(status); + } catch (GitAPIException | NoWorkTreeException | IOException e) { + throw die(e.getMessage(), e); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java index 43c1f54ab5..1da4b1d261 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java @@ -48,12 +48,14 @@ package org.eclipse.jgit.pgm; +import java.io.IOException; import java.text.MessageFormat; import java.util.List; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.ListTagCommand; import org.eclipse.jgit.api.TagCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.RefAlreadyExistsException; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; @@ -82,7 +84,7 @@ class Tag extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { try (Git git = new Git(db)) { if (tagName != null) { if (delete) { @@ -115,6 +117,8 @@ class Tag extends TextBuiltin { outw.println(Repository.shortenRefName(ref.getName())); } } + } catch (GitAPIException | IOException e) { + throw die(e.getMessage(), e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java index c4b4018b8f..05f237837f 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java @@ -196,7 +196,7 @@ public abstract class TextBuiltin { try { return Charset.forName(logOutputEncoding); } catch (IllegalArgumentException e) { - throw die(CLIText.get().cannotCreateOutputStream); + throw die(CLIText.get().cannotCreateOutputStream, e); } } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java index 5d032d2084..c13830242e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.pgm; import java.io.File; +import java.io.IOException; import java.text.MessageFormat; import org.eclipse.jgit.errors.RepositoryNotFoundException; @@ -70,20 +71,21 @@ class UploadPack extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { - final org.eclipse.jgit.transport.UploadPack up; - + protected void run() { try { FileKey key = FileKey.lenient(srcGitdir, FS.DETECTED); db = key.open(true /* must exist */); + org.eclipse.jgit.transport.UploadPack up = new org.eclipse.jgit.transport.UploadPack( + db); + if (0 <= timeout) { + up.setTimeout(timeout); + } + up.upload(ins, outs, errs); } catch (RepositoryNotFoundException notFound) { throw die(MessageFormat.format(CLIText.get().notAGitRepository, srcGitdir.getPath())); + } catch (IOException e) { + throw die(e.getMessage(), e); } - - up = new org.eclipse.jgit.transport.UploadPack(db); - if (0 <= timeout) - up.setTimeout(timeout); - up.upload(ins, outs, errs); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java index 58acc5cafd..cb447e46a8 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java @@ -57,21 +57,28 @@ import org.eclipse.jgit.pgm.internal.CLIText; class Version extends TextBuiltin { /** {@inheritDoc} */ @Override - protected void run() throws Exception { + protected void run() { // read the Implementation-Version from Manifest String version = getImplementationVersion(); // if Implementation-Version is not available then try reading // Bundle-Version - if (version == null) + if (version == null) { version = getBundleVersion(); + } // if both Implementation-Version and Bundle-Version are not available // then throw an exception - if (version == null) + if (version == null) { throw die(CLIText.get().cannotReadPackageInformation); + } - outw.println(MessageFormat.format(CLIText.get().jgitVersion, version)); + try { + outw.println( + MessageFormat.format(CLIText.get().jgitVersion, version)); + } catch (IOException e) { + throw die(e.getMessage(), e); + } } /** {@inheritDoc} */ 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 013ee1cf21..8a3e43e090 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 @@ -163,6 +163,7 @@ public class CLIText extends TranslationBundle { /***/ public String clonedEmptyRepository; /***/ public String cloningInto; /***/ public String commitLabel; + /***/ public String configOnlyListOptionSupported; /***/ public String conflictingUsageOf_git_dir_andArguments; /***/ public String couldNotCreateBranch; /***/ public String dateInfo; @@ -274,7 +275,7 @@ public class CLIText extends TranslationBundle { /***/ public String onBranchToBeBorn; /***/ public String onBranch; /***/ public String onlyOneMetaVarExpectedIn; - /***/ public String onlyOneOfIncludeOnlyAllInteractiveCanBeUsed; + /***/ public String onlyOneCommitOptionAllowed; /***/ public String password; /***/ public String pathspecDidNotMatch; /***/ public String pushTo; @@ -285,6 +286,7 @@ public class CLIText extends TranslationBundle { /***/ public String remoteSideDoesNotSupportDeletingRefs; /***/ public String removing; /***/ public String repaint; + /***/ public String resetNoMode; /***/ public String s3InvalidBucket; /***/ public String serviceNotSupported; /***/ public String skippingObject; diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/GpgSignHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/GpgSignHandler.java new file mode 100644 index 0000000000..e50301a0a4 --- /dev/null +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/GpgSignHandler.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2018, Salesforce. + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.eclipse.jgit.pgm.opt; + +import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.CmdLineParser; +import org.kohsuke.args4j.OptionDef; +import org.kohsuke.args4j.spi.Parameters; +import org.kohsuke.args4j.spi.Setter; +import org.kohsuke.args4j.spi.StringOptionHandler; + +/** + * Special handler for the <code>--gpg-sign</code> option of the + * <code>commit</code> command. + * + * The following rules apply: + * <ul> + * <li>If no key is given, i.e. just <code>--gpg-sign</code> is passed, then it + * is the same as <code>--gpg-sign=default</code></li> + * </ul> + * + * @since 5.3 + */ +public class GpgSignHandler extends StringOptionHandler { + + /** + * The value "default" which will be used when just the option is specified + * without any argument + */ + public static final String DEFAULT = "default"; //$NON-NLS-1$ + + /** + * <p> + * Constructor for GpgSignHandler. + * </p> + * + * @param parser + * The parser to which this handler belongs. + * @param option + * The annotation. + * @param setter + * Object to be used for setting value. + */ + public GpgSignHandler(CmdLineParser parser, OptionDef option, + Setter<? super String> setter) { + super(parser, option, setter); + } + + /** {@inheritDoc} */ + @Override + public int parseArguments(Parameters params) throws CmdLineException { + String alias = params.getParameter(-1); + if ("--gpg-sign".equals(alias) || "-S".equals(alias)) { //$NON-NLS-1$ //$NON-NLS-2$ + try { + String key = params.getParameter(0); + if (key == null || key.startsWith("-")) { //$NON-NLS-1$ + // ignore invalid values and assume default + setter.addValue(DEFAULT); + return 0; + } + + // use what we have + setter.addValue(key); + return 1; + } catch (CmdLineException e) { + // no additional value, assume default + setter.addValue(DEFAULT); + return 0; + } + } + return 0; + } + +} |