Skip to content

Commit

Permalink
Add command to remove remotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoberstar committed Feb 10, 2022
1 parent 0354fa7 commit c0450b1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.ajoberstar.grgit.operation

import java.util.concurrent.Callable

import org.ajoberstar.grgit.Repository
import org.ajoberstar.grgit.internal.Operation
import org.eclipse.jgit.lib.Config

/**
* Removes a remote from the repository.
* @see <a href="http://ajoberstar.org/grgit/grgit-remote.html">grgit-remote</a>
* @see <a href="http://git-scm.com/docs/git-remote">git-remote Manual Page</a>
*/
@Operation('remove')
class RemoteRemoveOp implements Callable<Void> {

private final Repository repository

/**
* Name of the remote.
*/
String name

RemoteRemoveOp(Repository repo) {
this.repository = repo
}

@Override
Void call() {
Config config = repository.jgit.repository.config
config.unsetSection("remote", name)
config.save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.ajoberstar.grgit.Repository
import org.ajoberstar.grgit.internal.WithOperations
import org.ajoberstar.grgit.operation.RemoteAddOp
import org.ajoberstar.grgit.operation.RemoteListOp
import org.ajoberstar.grgit.operation.RemoteRemoveOp

/**
* Provides support for remote-related operations on a Git repository.
Expand All @@ -17,9 +18,10 @@ import org.ajoberstar.grgit.operation.RemoteListOp
* <ul>
* <li>{@link org.ajoberstar.grgit.operation.RemoteAddOp add}</li>
* <li>{@link org.ajoberstar.grgit.operation.RemoteListOp list}</li>
* <li>{@link org.ajoberstar.grgit.operation.RemoteRemoveOp remove}</li>
* </ul>
*/
@WithOperations(instanceOperations=[RemoteListOp, RemoteAddOp])
@WithOperations(instanceOperations=[RemoteListOp, RemoteAddOp, RemoteRemoveOp])
class RemoteService {
private final Repository repository

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.ajoberstar.grgit.operation

import org.ajoberstar.grgit.fixtures.SimpleGitOpSpec

class RemoveRemoveOpSpec extends SimpleGitOpSpec {
def 'remote with given name is removed'() {
given:
grgit.remote.add(name: 'newRemote', url: 'http://fetch.url/')
when:
grgit.remote.remove(name: 'newRemote')
then:
[] == grgit.remote.list()
}
}

0 comments on commit c0450b1

Please sign in to comment.