1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.api;
11
12 import java.io.IOException;
13 import java.net.URISyntaxException;
14
15 import org.eclipse.jgit.api.errors.GitAPIException;
16 import org.eclipse.jgit.api.errors.JGitInternalException;
17 import org.eclipse.jgit.lib.ConfigConstants;
18 import org.eclipse.jgit.lib.Repository;
19 import org.eclipse.jgit.lib.StoredConfig;
20 import org.eclipse.jgit.transport.RemoteConfig;
21
22
23
24
25
26
27
28
29
30
31
32
33 public class RemoteRemoveCommand extends GitCommand<RemoteConfig> {
34
35 private String remoteName;
36
37
38
39
40
41
42
43
44
45 protected RemoteRemoveCommand(Repository repo) {
46 super(repo);
47 }
48
49
50
51
52
53
54
55
56 @Deprecated
57 public void setName(String name) {
58 this.remoteName = name;
59 }
60
61
62
63
64
65
66
67
68
69 public RemoteRemoveCommand setRemoteName(String remoteName) {
70 this.remoteName = remoteName;
71 return this;
72 }
73
74
75
76
77
78
79
80 @Override
81 public RemoteConfig call() throws GitAPIException {
82 checkCallable();
83
84 try {
85 StoredConfig config = repo.getConfig();
86 RemoteConfig remote = new RemoteConfig(config, remoteName);
87 config.unsetSection(ConfigConstants.CONFIG_KEY_REMOTE, remoteName);
88 config.save();
89 return remote;
90 } catch (IOException | URISyntaxException e) {
91 throw new JGitInternalException(e.getMessage(), e);
92 }
93
94 }
95
96 }