Skip to content

Commit

Permalink
Merge pull request #186 from ajoberstar/exceptions
Browse files Browse the repository at this point in the history
Remove custom exception type
  • Loading branch information
ajoberstar authored Jul 30, 2017
2 parents db9fda7 + 9f90a44 commit 0e4660e
Show file tree
Hide file tree
Showing 50 changed files with 120 additions and 382 deletions.
7 changes: 3 additions & 4 deletions src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/groovy/org/ajoberstar/grgit/exception/package-info.groovy

This file was deleted.

10 changes: 2 additions & 8 deletions src/main/groovy/org/ajoberstar/grgit/operation/AddOp.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -69,11 +67,7 @@ class AddOp implements Callable<Void> {
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
}
}
11 changes: 2 additions & 9 deletions src/main/groovy/org/ajoberstar/grgit/operation/ApplyOp.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -60,12 +57,8 @@ class ApplyOp implements Callable<Void> {
}
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -108,12 +105,8 @@ class BranchAddOp implements Callable<Branch> {
}
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -89,10 +86,10 @@ class BranchChangeOp implements Callable<Branch> {

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
Expand All @@ -103,12 +100,8 @@ class BranchChangeOp implements Callable<Branch> {
}
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 {
Expand Down
14 changes: 3 additions & 11 deletions src/main/groovy/org/ajoberstar/grgit/operation/BranchListOp.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -85,12 +81,8 @@ class BranchListOp implements Callable<List<Branch>> {
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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,10 +70,6 @@ class BranchRemoveOp implements Callable<List<String>> {
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -50,20 +48,16 @@ class BranchStatusOp implements Callable<BranchStatus> {
}

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")
}
}
}
11 changes: 2 additions & 9 deletions src/main/groovy/org/ajoberstar/grgit/operation/CheckoutOp.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -110,11 +107,7 @@ class CheckoutOp implements Callable<Void> {
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,10 +98,6 @@ class CleanOp implements Callable<Set<String>> {
cmd.dryRun = dryRun
cmd.ignore = ignore

try {
return cmd.call()
} catch (GitAPIException e) {
throw new GrgitException('Problem cleaning repository.', e)
}
return cmd.call()
}
}
13 changes: 3 additions & 10 deletions src/main/groovy/org/ajoberstar/grgit/operation/CloneOp.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -105,12 +102,8 @@ class CloneOp implements Callable<Grgit> {
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)
}
}
Loading

0 comments on commit 0e4660e

Please sign in to comment.