diff --git a/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy b/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy index 1f519407..3dad3d56 100644 --- a/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy @@ -16,7 +16,6 @@ package org.ajoberstar.grgit.auth import org.ajoberstar.grgit.Credentials -import org.ajoberstar.grgit.exception.GrgitException /** * Stores configuration options for how to authenticate with remote @@ -125,7 +124,7 @@ class AuthConfig { try { return [Option.valueOf(forceSetting.toUpperCase())] } catch (IllegalArgumentException e) { - throw new GrgitException("${FORCE_OPTION} must be set to one of ${Option.values() as List}. Currently set to: ${forceSetting}", e) + throw new IllegalArgumentException("${FORCE_OPTION} must be set to one of ${Option.values() as List}. Currently set to: ${forceSetting}", e) } } else { return (Option.values() as Set).findAll { @@ -196,7 +195,7 @@ class AuthConfig { * @param properties the properties to use in this configuration * @param env the environment vars to use in this configuration * @return the constructed configuration - * @throws GrgitException if force is set to an invalid option + * @throws IllegalArgumentException if force is set to an invalid option */ static AuthConfig fromMap(Map props, Map env = [:]) { return new AuthConfig(props, env) @@ -206,7 +205,7 @@ class AuthConfig { * Factory method to construct an authentication configuration from the * current system properties and environment variables. * @return the constructed configuration - * @throws GrgitException if force is set to an invalid option + * @throws IllegalArgumentException if force is set to an invalid option */ static AuthConfig fromSystem() { return fromMap(System.properties, System.env) diff --git a/src/main/groovy/org/ajoberstar/grgit/auth/JschAgentProxySessionFactory.groovy b/src/main/groovy/org/ajoberstar/grgit/auth/JschAgentProxySessionFactory.groovy index 4bfd95c0..ec51809c 100644 --- a/src/main/groovy/org/ajoberstar/grgit/auth/JschAgentProxySessionFactory.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/auth/JschAgentProxySessionFactory.groovy @@ -70,9 +70,11 @@ class JschAgentProxySessionFactory extends JschConfigSessionFactory { } if (config.sshPrivateKeyPath) { - if (config.getSshPassphrase()) + if (config.getSshPassphrase()) { jsch.addIdentity(config.sshPrivateKeyPath, config.getSshPassphrase()) - jsch.addIdentity(config.sshPrivateKeyPath) + } else { + jsch.addIdentity(config.sshPrivateKeyPath) + } } Connector con = determineConnector() diff --git a/src/main/groovy/org/ajoberstar/grgit/exception/GrgitException.groovy b/src/main/groovy/org/ajoberstar/grgit/exception/GrgitException.groovy deleted file mode 100644 index 41ee8c99..00000000 --- a/src/main/groovy/org/ajoberstar/grgit/exception/GrgitException.groovy +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.ajoberstar.grgit.exception - -import groovy.transform.CompileStatic -import groovy.transform.InheritConstructors - -/** - * Generic exception for any failures in use of Grgit. - */ -@InheritConstructors -@CompileStatic -class GrgitException extends RuntimeException {} diff --git a/src/main/groovy/org/ajoberstar/grgit/exception/package-info.groovy b/src/main/groovy/org/ajoberstar/grgit/exception/package-info.groovy deleted file mode 100644 index 1b4fa5cb..00000000 --- a/src/main/groovy/org/ajoberstar/grgit/exception/package-info.groovy +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.ajoberstar.grgit.exception diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/AddOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/AddOp.groovy index d0c89bc1..03ab2c76 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/AddOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/AddOp.groovy @@ -18,10 +18,8 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.eclipse.jgit.api.AddCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Adds files to the index. @@ -69,11 +67,7 @@ class AddOp implements Callable { AddCommand cmd = repo.jgit.add() patterns.each { cmd.addFilepattern(it) } cmd.update = update - try { - cmd.call() - return null - } catch (GitAPIException e) { - throw new GrgitException('Problem adding changes to index.', e) - } + cmd.call() + return null } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/ApplyOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/ApplyOp.groovy index 80909329..434072f4 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/ApplyOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/ApplyOp.groovy @@ -18,12 +18,9 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.util.CoercionUtil - import org.eclipse.jgit.api.ApplyCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Apply a patch to the index. @@ -60,12 +57,8 @@ class ApplyOp implements Callable { } CoercionUtil.toFile(patch).withInputStream { stream -> cmd.patch = stream - try { - cmd.call() - return null - } catch (GitAPIException e) { - throw new GrgitException('Problem applying patch.', e) - } + cmd.call() + return null } } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/BranchAddOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/BranchAddOp.groovy index f2aefd21..72ff864c 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/BranchAddOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/BranchAddOp.groovy @@ -19,14 +19,11 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Branch import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.CreateBranchCommand import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode -import org.eclipse.jgit.api.errors.GitAPIException import org.eclipse.jgit.lib.Ref /** @@ -108,12 +105,8 @@ class BranchAddOp implements Callable { } if (mode) { cmd.upstreamMode = mode.jgit } - try { - Ref ref = cmd.call() - return JGitUtil.resolveBranch(repo, ref) - } catch (GitAPIException e) { - throw new GrgitException('Problem creating branch.', e) - } + Ref ref = cmd.call() + return JGitUtil.resolveBranch(repo, ref) } static enum Mode { diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/BranchChangeOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/BranchChangeOp.groovy index fcecc347..a5924a19 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/BranchChangeOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/BranchChangeOp.groovy @@ -19,14 +19,11 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Branch import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.CreateBranchCommand import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode -import org.eclipse.jgit.api.errors.GitAPIException import org.eclipse.jgit.lib.Ref /** @@ -89,10 +86,10 @@ class BranchChangeOp implements Callable { Branch call() { if (!JGitUtil.resolveBranch(repo, name)) { - throw new GrgitException("Branch does not exist: ${name}") + throw new IllegalStateException("Branch does not exist: ${name}") } if (!startPoint) { - throw new GrgitException('Must set new startPoint.') + throw new IllegalArgumentException('Must set new startPoint.') } CreateBranchCommand cmd = repo.jgit.branchCreate() cmd.name = name @@ -103,12 +100,8 @@ class BranchChangeOp implements Callable { } if (mode) { cmd.upstreamMode = mode.jgit } - try { - Ref ref = cmd.call() - return JGitUtil.resolveBranch(repo, ref) - } catch (GitAPIException e) { - throw new GrgitException('Problem changing branch.', e) - } + Ref ref = cmd.call() + return JGitUtil.resolveBranch(repo, ref) } static enum Mode { diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/BranchListOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/BranchListOp.groovy index 9cc27217..b7e1e9b0 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/BranchListOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/BranchListOp.groovy @@ -15,18 +15,14 @@ */ package org.ajoberstar.grgit.operation -import org.ajoberstar.grgit.service.ResolveService - import java.util.concurrent.Callable import org.ajoberstar.grgit.Branch import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation +import org.ajoberstar.grgit.service.ResolveService import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.ListBranchCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Lists branches in the repository. Returns a list of {@link Branch}. @@ -85,12 +81,8 @@ class BranchListOp implements Callable> { if (contains) { cmd.contains = new ResolveService(repo).toRevisionString(contains) } - try { - return cmd.call().collect { - JGitUtil.resolveBranch(repo, it.name) - } - } catch (GitAPIException e) { - throw new GrgitException('Problem listing branches.', e) + return cmd.call().collect { + JGitUtil.resolveBranch(repo, it.name) } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/BranchRemoveOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/BranchRemoveOp.groovy index 3affa443..a4193cce 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/BranchRemoveOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/BranchRemoveOp.groovy @@ -18,12 +18,9 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService - import org.eclipse.jgit.api.DeleteBranchCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Removes one or more branches from the repository. Returns a list of @@ -73,10 +70,6 @@ class BranchRemoveOp implements Callable> { cmd.branchNames = names.collect { new ResolveService(repo).toBranchName(it) } cmd.force = force - try { - return cmd.call() - } catch (GitAPIException e) { - throw new GrgitException('Problem deleting branch(es).', e) - } + return cmd.call() } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/BranchStatusOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/BranchStatusOp.groovy index 740abdb6..a025bebc 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/BranchStatusOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/BranchStatusOp.groovy @@ -20,10 +20,8 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Branch import org.ajoberstar.grgit.BranchStatus import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService - import org.eclipse.jgit.lib.BranchTrackingStatus /** @@ -50,20 +48,16 @@ class BranchStatusOp implements Callable { } BranchStatus call() { - try { - Branch realBranch = new ResolveService(repo).toBranch(name) - if (realBranch.trackingBranch) { - BranchTrackingStatus status = BranchTrackingStatus.of(repo.jgit.repository, realBranch.fullName) - if (status) { - return new BranchStatus(realBranch, status.aheadCount, status.behindCount) - } else { - throw new GrgitException("Could not retrieve status for ${name}") - } + Branch realBranch = new ResolveService(repo).toBranch(name) + if (realBranch.trackingBranch) { + BranchTrackingStatus status = BranchTrackingStatus.of(repo.jgit.repository, realBranch.fullName) + if (status) { + return new BranchStatus(realBranch, status.aheadCount, status.behindCount) } else { - throw new GrgitException("${name} is not set to track another branch") + throw new IllegalStateException("Could not retrieve status for ${name}") } - } catch (IOException e) { - throw new GrgitException('Problem retrieving branch status.', e) + } else { + throw new IllegalStateException("${name} is not set to track another branch") } } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/CheckoutOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/CheckoutOp.groovy index dada0cf6..081a0bf4 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/CheckoutOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/CheckoutOp.groovy @@ -18,12 +18,9 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService - import org.eclipse.jgit.api.CheckoutCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Checks out a branch to the working tree. Does not support checking out @@ -110,11 +107,7 @@ class CheckoutOp implements Callable { cmd.createBranch = createBranch cmd.startPoint = resolve.toRevisionString(startPoint) cmd.orphan = orphan - try { - cmd.call() - return null - } catch (GitAPIException e) { - throw new GrgitException('Problem checking out.', e) - } + cmd.call() + return null } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/CleanOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/CleanOp.groovy index 7c7dde26..1134f531 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/CleanOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/CleanOp.groovy @@ -18,10 +18,8 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.eclipse.jgit.api.CleanCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Remove untracked files from the working tree. Returns the list of @@ -100,10 +98,6 @@ class CleanOp implements Callable> { cmd.dryRun = dryRun cmd.ignore = ignore - try { - return cmd.call() - } catch (GitAPIException e) { - throw new GrgitException('Problem cleaning repository.', e) - } + return cmd.call() } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/CloneOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/CloneOp.groovy index 8063cd95..5370402b 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/CloneOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/CloneOp.groovy @@ -21,13 +21,10 @@ import org.ajoberstar.grgit.Credentials import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.Repository import org.ajoberstar.grgit.auth.TransportOpUtil -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.util.CoercionUtil - import org.eclipse.jgit.api.CloneCommand import org.eclipse.jgit.api.Git -import org.eclipse.jgit.api.errors.GitAPIException /** * Clones an existing repository. Returns a {@link Grgit} pointing @@ -105,12 +102,8 @@ class CloneOp implements Callable { cmd.noCheckout = !checkout if (refToCheckout) { cmd.branch = refToCheckout } - try { - Git jgit = cmd.call() - Repository repo = new Repository(CoercionUtil.toFile(dir), jgit, credentials) - return new Grgit(repo) - } catch (GitAPIException e) { - throw new GrgitException('Problem cloning repository.', e) - } + Git jgit = cmd.call() + Repository repo = new Repository(CoercionUtil.toFile(dir), jgit, credentials) + return new Grgit(repo) } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/CommitOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/CommitOp.groovy index 805ef82d..434f30af 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/CommitOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/CommitOp.groovy @@ -20,12 +20,9 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Commit import org.ajoberstar.grgit.Person import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.CommitCommand -import org.eclipse.jgit.api.errors.GitAPIException import org.eclipse.jgit.lib.PersonIdent import org.eclipse.jgit.revwalk.RevCommit @@ -119,11 +116,7 @@ class CommitOp implements Callable { paths.each { cmd.setOnly(it) } if (all) { cmd.all = all } cmd.amend = amend - try { - RevCommit commit = cmd.call() - return JGitUtil.convertCommit(commit) - } catch (GitAPIException e) { - throw new GrgitException('Problem committing changes.', e) - } + RevCommit commit = cmd.call() + return JGitUtil.convertCommit(commit) } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/DescribeOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/DescribeOp.groovy index 8ab63471..f6f59852 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/DescribeOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/DescribeOp.groovy @@ -18,12 +18,9 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService - import org.eclipse.jgit.api.DescribeCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Find the nearest tag reachable. Returns an {@link String}}. @@ -73,15 +70,10 @@ class DescribeOp implements Callable { String call(){ DescribeCommand cmd = repo.jgit.describe() - try { - if (commit) { - cmd.setTarget(new ResolveService(repo).toRevisionString(commit)) - } - cmd.setLong(longDescr) - return cmd.call() - } catch (GitAPIException e) { - throw new GrgitException('Problem retrieving description.', e) + if (commit) { + cmd.setTarget(new ResolveService(repo).toRevisionString(commit)) } - + cmd.setLong(longDescr) + return cmd.call() } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/FetchOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/FetchOp.groovy index e2c22758..3938d242 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/FetchOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/FetchOp.groovy @@ -19,10 +19,8 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository import org.ajoberstar.grgit.auth.TransportOpUtil -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.eclipse.jgit.api.FetchCommand -import org.eclipse.jgit.api.errors.GitAPIException import org.eclipse.jgit.transport.RefSpec import org.eclipse.jgit.transport.TagOpt @@ -94,12 +92,8 @@ class FetchOp implements Callable { cmd.refSpecs = refSpecs.collect { new RefSpec(it) } cmd.removeDeletedRefs = prune cmd.tagOpt = tagMode.jgit - try { - cmd.call() - return null - } catch (GitAPIException e) { - throw new GrgitException('Problem fetching from remote.', e) - } + cmd.call() + return null } enum TagMode { diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/InitOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/InitOp.groovy index 00883184..e0bed0cb 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/InitOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/InitOp.groovy @@ -19,13 +19,10 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.util.CoercionUtil - import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.InitCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Initializes a new repository. Returns a {@link Grgit} pointing @@ -67,12 +64,8 @@ class InitOp implements Callable { InitCommand cmd = Git.init() cmd.bare = bare cmd.directory = CoercionUtil.toFile(dir) - try { - Git jgit = cmd.call() - Repository repo = new Repository(CoercionUtil.toFile(dir), jgit, null) - return new Grgit(repo) - } catch (GitAPIException e) { - throw new GrgitException('Problem initializing repository.', e) - } + Git jgit = cmd.call() + Repository repo = new Repository(CoercionUtil.toFile(dir), jgit, null) + return new Grgit(repo) } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/LogOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/LogOp.groovy index b30fda75..9141a7c8 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/LogOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/LogOp.groovy @@ -19,13 +19,10 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Commit import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.LogCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Gets a log of commits in the repository. Returns a list of {@link Commit}s. @@ -107,10 +104,6 @@ class LogOp implements Callable> { } cmd.skip = skipCommits cmd.maxCount = maxCommits - try { - return cmd.call().collect { JGitUtil.convertCommit(it) }.asImmutable() - } catch (GitAPIException e) { - throw new GrgitException('Problem retrieving log.', e) - } + return cmd.call().collect { JGitUtil.convertCommit(it) }.asImmutable() } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/LsRemoteOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/LsRemoteOp.groovy index 56656e66..0d62a54b 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/LsRemoteOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/LsRemoteOp.groovy @@ -19,10 +19,8 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Ref import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.eclipse.jgit.api.LsRemoteCommand -import org.eclipse.jgit.api.errors.GitAPIException import org.eclipse.jgit.lib.ObjectId /** @@ -76,17 +74,13 @@ class LsRemoteOp implements Callable> { } Map call() { - LsRemoteCommand cmd = repo.jgit.lsRemote() - cmd.remote = remote - cmd.heads = heads - cmd.tags = tags - try { - return cmd.call().collectEntries { jgitRef -> - Ref ref = new Ref(jgitRef.getName()) - [(ref): ObjectId.toString(jgitRef.getObjectId())] - }.asImmutable() - } catch (GitAPIException e) { - throw new GrgitException('Problem retrieving ls-remote.', e) - } + LsRemoteCommand cmd = repo.jgit.lsRemote() + cmd.remote = remote + cmd.heads = heads + cmd.tags = tags + return cmd.call().collectEntries { jgitRef -> + Ref ref = new Ref(jgitRef.getName()) + [(ref): ObjectId.toString(jgitRef.getObjectId())] + }.asImmutable() } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/MergeOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/MergeOp.groovy index 250a435b..b9590b41 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/MergeOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/MergeOp.groovy @@ -18,14 +18,11 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.MergeCommand import org.eclipse.jgit.api.MergeResult -import org.eclipse.jgit.api.errors.GitAPIException /** * Merges changes from a single head. This is a simplified version of @@ -106,15 +103,11 @@ class MergeOp implements Callable { break } - try { - MergeResult result = cmd.call() - if (!result.mergeStatus.successful) { - throw new GrgitException("Could not merge (conflicting files can be retrieved with a call to grgit.status()): ${result}") - } - return null - } catch (GitAPIException e) { - throw new GrgitException('Problem merging.', e) + MergeResult result = cmd.call() + if (!result.mergeStatus.successful) { + throw new IllegalStateException("Could not merge (conflicting files can be retrieved with a call to grgit.status()): ${result}") } + return null } static enum Mode { diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/OpenOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/OpenOp.groovy index 266adc13..dcd859c2 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/OpenOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/OpenOp.groovy @@ -20,7 +20,6 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Credentials import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.util.CoercionUtil import org.eclipse.jgit.api.Git @@ -96,7 +95,7 @@ class OpenOp implements Callable { } if(builder.getGitDir() == null){ - throw new GrgitException('No .git directory found!'); + throw new IllegalStateException('No .git directory found!'); } FileRepository jgitRepo = builder.build() diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/PullOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/PullOp.groovy index e5a160b8..9aab9ce6 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/PullOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/PullOp.groovy @@ -19,11 +19,9 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository import org.ajoberstar.grgit.auth.TransportOpUtil -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.eclipse.jgit.api.PullCommand import org.eclipse.jgit.api.PullResult -import org.eclipse.jgit.api.errors.GitAPIException /** * Pulls changes from the remote on the current branch. If the changes @@ -93,14 +91,10 @@ class PullOp implements Callable { cmd.rebase = rebase TransportOpUtil.configure(cmd, repo.credentials) - try { PullResult result = cmd.call() if (!result.successful) { - throw new GrgitException("Could not pull: ${result}") + throw new IllegalStateException("Could not pull: ${result}") } return null - } catch (GitAPIException e) { - throw new GrgitException('Problem merging.', e) - } } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/PushOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/PushOp.groovy index 4ab5bda9..4048611b 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/PushOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/PushOp.groovy @@ -19,10 +19,8 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository import org.ajoberstar.grgit.auth.TransportOpUtil -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.eclipse.jgit.api.PushCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Push changes to a remote repository. @@ -111,11 +109,7 @@ class PushOp implements Callable { if (tags) { cmd.setPushTags() } cmd.force = force cmd.dryRun = dryRun - try { - cmd.call() - return null - } catch (GitAPIException e) { - throw new GrgitException('Problem pushing to remote.', e) - } + cmd.call() + return null } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/RemoteAddOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/RemoteAddOp.groovy index b84bac8f..a3836453 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/RemoteAddOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/RemoteAddOp.groovy @@ -19,10 +19,8 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Remote import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.lib.Config import org.eclipse.jgit.transport.RefSpec import org.eclipse.jgit.transport.RemoteConfig @@ -85,7 +83,7 @@ class RemoteAddOp implements Callable { Remote call() { Config config = repository.jgit.repository.config if (RemoteConfig.getAllRemoteConfigs(config).find { it.name == name }) { - throw new GrgitException("Remote $name already exists.") + throw new IllegalStateException("Remote $name already exists.") } def toUri = { url -> new URIish(url) } def toRefSpec = { spec -> new RefSpec(spec) } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/RemoteListOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/RemoteListOp.groovy index 87062020..fb868ab2 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/RemoteListOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/RemoteListOp.groovy @@ -18,10 +18,8 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.transport.RemoteConfig /** @@ -49,7 +47,7 @@ class RemoteListOp implements Callable { List call() { return RemoteConfig.getAllRemoteConfigs(repository.jgit.repository.config).collect { rc -> if (rc.uris.size() > 1 || rc.pushURIs.size() > 1) { - throw new GrgitException("Grgit does not currently support multiple URLs in remote: [uris: ${rc.uris}, pushURIs:${rc.pushURIs}]") + throw new IllegalArgumentException("Grgit does not currently support multiple URLs in remote: [uris: ${rc.uris}, pushURIs:${rc.pushURIs}]") } JGitUtil.convertRemote(rc) } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/ResetOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/ResetOp.groovy index a9862814..01466ab7 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/ResetOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/ResetOp.groovy @@ -18,12 +18,9 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService - import org.eclipse.jgit.api.ResetCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Reset changes in the repository. @@ -96,12 +93,8 @@ class ResetOp implements Callable { cmd.mode = mode.jgit } - try { - cmd.call() - return null - } catch (GitAPIException e) { - throw new GrgitException('Problem running reset.', e) - } + cmd.call() + return null } static enum Mode { diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/RevertOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/RevertOp.groovy index c7d0a730..3e69e0e2 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/RevertOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/RevertOp.groovy @@ -19,13 +19,10 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Commit import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.RevertCommand -import org.eclipse.jgit.api.errors.GitAPIException import org.eclipse.jgit.revwalk.RevCommit /** @@ -62,14 +59,7 @@ class RevertOp implements Callable { String revstr = new ResolveService(repo).toRevisionString(it) cmd.include(JGitUtil.resolveObject(repo, revstr)) } - try { - RevCommit commit = cmd.call() - if (commit == null) { - throw new GrgitException('Problem reverting commits.') - } - return JGitUtil.convertCommit(commit) - } catch (GitAPIException e) { - throw new GrgitException('Problem reverting commits.', e) - } + RevCommit commit = cmd.call() + return JGitUtil.convertCommit(commit) } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/RmOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/RmOp.groovy index 52de4d74..e5c7a1a9 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/RmOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/RmOp.groovy @@ -18,10 +18,8 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.eclipse.jgit.api.RmCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Remove files from the index and (optionally) delete them from the working tree. @@ -68,11 +66,7 @@ class RmOp implements Callable { RmCommand cmd = repo.jgit.rm() patterns.each { cmd.addFilepattern(it) } cmd.cached = cached - try { - cmd.call() - return null - } catch (GitAPIException e) { - throw new GrgitException('Problem removing files from index.', e) - } + cmd.call() + return null } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/ShowOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/ShowOp.groovy index 2d393087..ae4b3220 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/ShowOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/ShowOp.groovy @@ -19,14 +19,12 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.CommitDiff import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.diff.DiffEntry -import org.eclipse.jgit.diff.DiffEntry.ChangeType import org.eclipse.jgit.diff.RenameDetector +import org.eclipse.jgit.diff.DiffEntry.ChangeType import org.eclipse.jgit.treewalk.TreeWalk /** @@ -65,7 +63,7 @@ class ShowOp implements Callable { CommitDiff call() { if (!commit) { - throw new GrgitException('You must specify which commit to show') + throw new IllegalArgumentException('You must specify which commit to show') } def revString = new ResolveService(repo).toRevisionString(commit) def commitId = JGitUtil.resolveRevObject(repo, revString) diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/StatusOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/StatusOp.groovy index 22719de3..8d86163f 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/StatusOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/StatusOp.groovy @@ -19,12 +19,9 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository import org.ajoberstar.grgit.Status -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.StatusCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Gets the current status of the repository. Returns an {@link Status}. @@ -50,10 +47,6 @@ class StatusOp implements Callable { Status call() { StatusCommand cmd = repo.jgit.status() - try { - return JGitUtil.convertStatus(cmd.call()) - } catch (GitAPIException e) { - throw new GrgitException('Problem retrieving status.', e) - } + return JGitUtil.convertStatus(cmd.call()) } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/TagAddOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/TagAddOp.groovy index 2871a607..e4ab1e1b 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/TagAddOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/TagAddOp.groovy @@ -20,13 +20,10 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Person import org.ajoberstar.grgit.Repository import org.ajoberstar.grgit.Tag -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.TagCommand -import org.eclipse.jgit.api.errors.GitAPIException import org.eclipse.jgit.lib.PersonIdent import org.eclipse.jgit.lib.Ref @@ -117,11 +114,7 @@ class TagAddOp implements Callable { cmd.objectId = JGitUtil.resolveRevObject(repo, revstr) } - try { - Ref ref = cmd.call() - return JGitUtil.resolveTag(repo, ref) - } catch (GitAPIException e) { - throw new GrgitException('Problem creating tag.', e) - } + Ref ref = cmd.call() + return JGitUtil.resolveTag(repo, ref) } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/TagListOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/TagListOp.groovy index ea386d0e..03f8c6d5 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/TagListOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/TagListOp.groovy @@ -19,12 +19,9 @@ import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository import org.ajoberstar.grgit.Tag -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.util.JGitUtil - import org.eclipse.jgit.api.ListTagCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Lists tags in the repository. Returns a list of {@link Tag}. @@ -51,12 +48,8 @@ class TagListOp implements Callable> { List call() { ListTagCommand cmd = repo.jgit.tagList() - try { - return cmd.call().collect { - JGitUtil.resolveTag(repo, it) - } - } catch (GitAPIException e) { - throw new GrgitException('Problem listing tags.', e) + return cmd.call().collect { + JGitUtil.resolveTag(repo, it) } } } diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/TagRemoveOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/TagRemoveOp.groovy index 7acd9717..53ec4de0 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/TagRemoveOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/TagRemoveOp.groovy @@ -18,12 +18,9 @@ package org.ajoberstar.grgit.operation import java.util.concurrent.Callable import org.ajoberstar.grgit.Repository -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.internal.Operation import org.ajoberstar.grgit.service.ResolveService - import org.eclipse.jgit.api.DeleteTagCommand -import org.eclipse.jgit.api.errors.GitAPIException /** * Removes one or more tags from the repository. Returns a list of @@ -58,10 +55,6 @@ class TagRemoveOp implements Callable> { DeleteTagCommand cmd = repo.jgit.tagDelete() cmd.tags = names.collect { new ResolveService(repo).toTagName(it) } - try { - return cmd.call() - } catch (GitAPIException e) { - throw new GrgitException('Problem deleting tag(s).', e) - } + return cmd.call() } } diff --git a/src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy b/src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy index a214abe3..a510eecb 100644 --- a/src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy @@ -27,11 +27,7 @@ import org.ajoberstar.grgit.Remote import org.ajoberstar.grgit.Repository import org.ajoberstar.grgit.Status import org.ajoberstar.grgit.Tag -import org.ajoberstar.grgit.exception.GrgitException -import org.eclipse.jgit.errors.AmbiguousObjectException import org.eclipse.jgit.errors.IncorrectObjectTypeException -import org.eclipse.jgit.errors.MissingObjectException -import org.eclipse.jgit.errors.RevisionSyntaxException import org.eclipse.jgit.lib.BranchConfig import org.eclipse.jgit.lib.Config import org.eclipse.jgit.lib.ObjectId @@ -57,25 +53,10 @@ class JGitUtil { * @param repo the Grgit repository to resolve the object from * @param revstr the revision string to use * @return the resolved object - * @throws GrgitException if the object cannot be resolved */ static ObjectId resolveObject(Repository repo, String revstr) { - try { - ObjectId object = repo.jgit.repository.resolve(revstr) - if (object == null) { - throw new GrgitException("No commit found for revision string: ${revstr}") - } else { - return object - } - } catch (AmbiguousObjectException e) { - throw new GrgitException("Revision string is ambiguous: ${revstr}", e) - } catch (RevisionSyntaxException e) { - throw new GrgitException("Revision string syntax isn't supported: ${revstr}", e) - } catch (IncorrectObjectTypeException e) { - throw new GrgitException("Revision string did not point to a commit: ${revstr}", e) - } catch (IOException e) { - throw new GrgitException("Problem resolving revision string: ${revstr}", e) - } + ObjectId object = repo.jgit.repository.resolve(revstr) + return object } /** @@ -84,19 +65,12 @@ class JGitUtil { * @param revstr the revision string to use * @param peel whether or not to peel the resolved object * @return the resolved object - * @throws GrgitException if the object cannot be resolved */ static RevObject resolveRevObject(Repository repo, String revstr, boolean peel = false) { ObjectId id = resolveObject(repo, revstr) RevWalk walk = new RevWalk(repo.jgit.repository) - try { - RevObject rev = walk.parseAny(id) - return peel ? walk.peel(rev) : rev - } catch (MissingObjectException e) { - throw new GrgitException("Supplied object does not exist: ${revstr}", e) - } catch (IOException e) { - throw new GrgitException("Could not read pack file or loose object for: ${revstr}", e) - } + RevObject rev = walk.parseAny(id) + return peel ? walk.peel(rev) : rev } /** @@ -104,7 +78,6 @@ class JGitUtil { * @param repo the Grgit repository to resolve the parents from * @param id the object to get the parents of * @return the parents of the commit - * @throws GrgitException if the parents cannot be resolved */ static Set resolveParents(Repository repo, ObjectId id) { RevWalk walk = new RevWalk(repo.jgit.repository) @@ -119,7 +92,6 @@ class JGitUtil { * @param repo the Grgit repository to resolve the commit from * @param revstr the revision string to use * @return the resolved commit - * @throws GrgitException if the commit cannot be resolved */ static Commit resolveCommit(Repository repo, String revstr) { ObjectId id = resolveObject(repo, revstr) @@ -131,7 +103,6 @@ class JGitUtil { * @param repo the Grgit repository to resolve the commit from * @param id the object id of the commit to resolve * @return the resolved commit - * @throws GrgitException if the commit cannot be resolved */ static Commit resolveCommit(Repository repo, ObjectId id) { RevWalk walk = new RevWalk(repo.jgit.repository) @@ -168,7 +139,6 @@ class JGitUtil { * @param repo the Grgit repository to resolve from * @param name the name of the tag to resolve * @return the resolved tag - * @throws GrgitException if the tag cannot be resolved */ static Tag resolveTag(Repository repo, String name) { Ref ref = repo.jgit.repository.getRef(name) @@ -211,7 +181,6 @@ class JGitUtil { * @param repo the Grgit repository to resolve from * @param name the name of the branch to resolve * @return the resolved branch - * @throws GrgitException if the branch cannot be resolved */ static Branch resolveBranch(Repository repo, String name) { Ref ref = repo.jgit.repository.getRef(name) diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/BranchAddOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/BranchAddOpSpec.groovy index 18dd9361..7cf9355c 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/BranchAddOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/BranchAddOpSpec.groovy @@ -16,9 +16,9 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Grgit -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.GitTestUtil import org.ajoberstar.grgit.fixtures.MultiGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException import spock.lang.Unroll @@ -64,7 +64,7 @@ class BranchAddOpSpec extends MultiGitOpSpec { when: localGrgit.branch.add(name: 'test-branch') then: - thrown(GrgitException) + thrown(GitAPIException) } def 'branch add with mode set but no start point fails'() { @@ -98,7 +98,7 @@ class BranchAddOpSpec extends MultiGitOpSpec { when: localGrgit.branch.add(startPoint: 'origin/my-branch', mode: mode) then: - thrown(GrgitException) + thrown(GitAPIException) where: mode << [null, BranchAddOp.Mode.TRACK, BranchAddOp.Mode.NO_TRACK] } diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/BranchChangeOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/BranchChangeOpSpec.groovy index c3e4d5c6..a6088ccc 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/BranchChangeOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/BranchChangeOpSpec.groovy @@ -16,9 +16,9 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Grgit -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.GitTestUtil import org.ajoberstar.grgit.fixtures.MultiGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException import spock.lang.Unroll @@ -52,14 +52,14 @@ class BranchChangeOpSpec extends MultiGitOpSpec { when: localGrgit.branch.change(name: 'fake-branch', startPoint: 'test-branch') then: - thrown(GrgitException) + thrown(IllegalStateException) } def 'branch change with no start point fails'() { when: localGrgit.branch.change(name: 'local-branch') then: - thrown(GrgitException) + thrown(IllegalArgumentException) } @Unroll('branch change with #mode mode starting at #startPoint tracks #trackingBranch') diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/BranchRemoveOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/BranchRemoveOpSpec.groovy index 570cb48f..1d45d450 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/BranchRemoveOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/BranchRemoveOpSpec.groovy @@ -16,9 +16,9 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Branch -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.GitTestUtil import org.ajoberstar.grgit.fixtures.SimpleGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException import spock.lang.Unroll @@ -69,7 +69,7 @@ class BranchRemoveOpSpec extends SimpleGitOpSpec { when: grgit.branch.remove(names: ['branch3']) then: - thrown(GrgitException) + thrown(GitAPIException) } def 'branch remove with unmerged branch and force true works'() { @@ -83,7 +83,7 @@ class BranchRemoveOpSpec extends SimpleGitOpSpec { when: grgit.branch.remove(names: ['master'], force: force) then: - thrown(GrgitException) + thrown(GitAPIException) where: force << [true, false] } diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/BranchStatusOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/BranchStatusOpSpec.groovy index 919ca389..78b0228c 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/BranchStatusOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/BranchStatusOpSpec.groovy @@ -17,9 +17,9 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.BranchStatus import org.ajoberstar.grgit.Grgit -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.GitTestUtil import org.ajoberstar.grgit.fixtures.MultiGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException import spock.lang.Unroll @@ -64,7 +64,7 @@ class BranchStatusOpSpec extends MultiGitOpSpec { when: localGrgit.branch.status(name: 'no-track') then: - thrown(GrgitException) + thrown(IllegalStateException) } @Unroll('branch status on #branch gives correct counts') diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/CheckoutOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/CheckoutOpSpec.groovy index 5160c4de..fa885bfd 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/CheckoutOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/CheckoutOpSpec.groovy @@ -16,8 +16,8 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Status -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.SimpleGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException class CheckoutOpSpec extends SimpleGitOpSpec { def setup() { @@ -50,14 +50,14 @@ class CheckoutOpSpec extends SimpleGitOpSpec { when: grgit.checkout(branch: 'my-branch', createBranch: true) then: - thrown(GrgitException) + thrown(GitAPIException) } def 'checkout with non-existent branch and createBranch false fails'() { when: grgit.checkout(branch: 'fake') then: - thrown(GrgitException) + thrown(GitAPIException) } def 'checkout with non-existent branch and createBranch true works'() { @@ -91,7 +91,7 @@ class CheckoutOpSpec extends SimpleGitOpSpec { when: grgit.checkout(branch: 'my-branch', orphan: true) then: - thrown(GrgitException) + thrown(GitAPIException) } def 'checkout with non-existent branch and orphan true works'() { diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/CloneOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/CloneOpSpec.groovy index d9772d17..721240ab 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/CloneOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/CloneOpSpec.groovy @@ -16,9 +16,9 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Grgit -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.GitTestUtil import org.ajoberstar.grgit.fixtures.MultiGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException class CloneOpSpec extends MultiGitOpSpec { File repoDir @@ -57,7 +57,7 @@ class CloneOpSpec extends MultiGitOpSpec { when: Grgit.clone(dir: repoDir, uri: 'file:///bad/uri') then: - thrown(GrgitException) + thrown(GitAPIException) } def 'clone with default settings clones as expected'() { diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/FetchOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/FetchOpSpec.groovy index 32c5fa43..f9b039bc 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/FetchOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/FetchOpSpec.groovy @@ -16,10 +16,10 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Grgit -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.GitTestUtil import org.ajoberstar.grgit.fixtures.MultiGitOpSpec import org.ajoberstar.grgit.operation.FetchOp.TagMode +import org.eclipse.jgit.api.errors.GitAPIException import spock.lang.Unroll @@ -67,7 +67,7 @@ class FetchOpSpec extends MultiGitOpSpec { when: localGrgit.fetch(remote: 'fake') then: - thrown(GrgitException) + thrown(GitAPIException) } def 'fetch without other settings, brings down correct commits'() { diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/LsRemoteOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/LsRemoteOpSpec.groovy index 65095072..677c07b4 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/LsRemoteOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/LsRemoteOpSpec.groovy @@ -17,8 +17,8 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.Ref -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.MultiGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException import spock.lang.Unroll @@ -73,7 +73,7 @@ class LsRemoteOpSpec extends MultiGitOpSpec { when: localGrgit.lsremote(remote: 'fake') then: - thrown(GrgitException) + thrown(GitAPIException) } def 'lsremote returns all refs'() { diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/MergeOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/MergeOpSpec.groovy index 46de933c..212cf76f 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/MergeOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/MergeOpSpec.groovy @@ -19,8 +19,8 @@ import static org.ajoberstar.grgit.operation.MergeOp.Mode.* import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.Status -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.MultiGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException import spock.lang.Unroll @@ -151,7 +151,7 @@ class MergeOpSpec extends MultiGitOpSpec { then: localGrgit.head() == oldHead localGrgit.status() == status - thrown(GrgitException) + thrown(IllegalStateException) where: head | mode | status 'origin/clean' | ONLY_FF | new Status() diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/OpenOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/OpenOpSpec.groovy index f39ff958..d4dde175 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/OpenOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/OpenOpSpec.groovy @@ -21,10 +21,10 @@ import org.ajoberstar.grgit.Commit import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.Status import org.ajoberstar.grgit.fixtures.SimpleGitOpSpec -import org.ajoberstar.grgit.exception.GrgitException import org.eclipse.jgit.api.Git import org.eclipse.jgit.errors.RepositoryNotFoundException +import org.eclipse.jgit.api.errors.GitAPIException import spock.util.environment.RestoreSystemProperties @@ -62,7 +62,7 @@ class OpenOpSpec extends SimpleGitOpSpec { when: Grgit.open() then: - thrown(GrgitException) + thrown(IllegalStateException) } @RestoreSystemProperties diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/PullOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/PullOpSpec.groovy index ac19979e..e6acce1c 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/PullOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/PullOpSpec.groovy @@ -18,8 +18,8 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Commit import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.Status -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.MultiGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException class PullOpSpec extends MultiGitOpSpec { Grgit localGrgit @@ -106,7 +106,7 @@ class PullOpSpec extends MultiGitOpSpec { then: localGrgit.status() == new Status(conflicts: ['1.txt']) localGrgit.head() == localHead - thrown(GrgitException) + thrown(IllegalStateException) } def 'pull to local repo with clean changes and rebase rebases changes on top of origin'() { diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/PushOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/PushOpSpec.groovy index b0bf5a67..5888cadf 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/PushOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/PushOpSpec.groovy @@ -16,9 +16,9 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Grgit -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.GitTestUtil import org.ajoberstar.grgit.fixtures.MultiGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException class PushOpSpec extends MultiGitOpSpec { Grgit localGrgit @@ -54,7 +54,7 @@ class PushOpSpec extends MultiGitOpSpec { when: localGrgit.push(remote: 'fake') then: - thrown(GrgitException) + thrown(GitAPIException) } def 'push without other settings pushes correct commits'() { diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/StatusOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/StatusOpSpec.groovy index d72bee27..7dc0929c 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/StatusOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/StatusOpSpec.groovy @@ -16,8 +16,8 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Status -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.SimpleGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException class StatusOpSpec extends SimpleGitOpSpec { def setup() { @@ -98,6 +98,6 @@ class StatusOpSpec extends SimpleGitOpSpec { grgit.merge(head: 'conflict') then: grgit.status() == new Status(conflicts: ['1.txt']) - thrown(GrgitException) + thrown(IllegalStateException) } } diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/TagAddOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/TagAddOpSpec.groovy index 1ea71aa7..f51c3327 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/TagAddOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/TagAddOpSpec.groovy @@ -21,8 +21,8 @@ import java.time.ZonedDateTime import java.time.temporal.ChronoField import org.ajoberstar.grgit.Tag -import org.ajoberstar.grgit.exception.GrgitException import org.ajoberstar.grgit.fixtures.SimpleGitOpSpec +import org.eclipse.jgit.api.errors.GitAPIException class TagAddOpSpec extends SimpleGitOpSpec { List commits = [] @@ -97,7 +97,7 @@ class TagAddOpSpec extends SimpleGitOpSpec { when: grgit.tag.add(name: 'test-tag') then: - thrown(GrgitException) + thrown(GitAPIException) } def 'tag add with force overwrites existing tag'() { diff --git a/src/test/groovy/org/ajoberstar/grgit/util/JGitUtilSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/util/JGitUtilSpec.groovy index f87aba37..4ae6b740 100644 --- a/src/test/groovy/org/ajoberstar/grgit/util/JGitUtilSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/util/JGitUtilSpec.groovy @@ -25,8 +25,8 @@ import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.Person import org.ajoberstar.grgit.Repository import org.ajoberstar.grgit.Tag -import org.ajoberstar.grgit.exception.GrgitException import org.eclipse.jgit.api.Git +import org.eclipse.jgit.api.errors.GitAPIException import org.eclipse.jgit.errors.RevisionSyntaxException import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.lib.Ref @@ -93,19 +93,15 @@ class JGitUtilSpec extends Specification { } def 'resolveObject fails if revision cannot be found'() { - when: - JGitUtil.resolveObject(repo, 'unreal') - then: - def e = thrown(GrgitException) - e.cause == null + expect: + JGitUtil.resolveObject(repo, 'unreal') == null } def 'resolveObject fails if revision syntax is wrong'() { when: JGitUtil.resolveObject(repo, 'lkj!)#(*') then: - def e = thrown(GrgitException) - e.cause instanceof RevisionSyntaxException + thrown(RevisionSyntaxException) } def 'convertCommit works for valid commit'() {