本文整理汇总了Java中org.eclipse.jgit.lib.StoredConfig类的典型用法代码示例。如果您正苦于以下问题:Java StoredConfig类的具体用法?Java StoredConfig怎么用?Java StoredConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StoredConfig类属于org.eclipse.jgit.lib包,在下文中一共展示了StoredConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
private void execute() throws InvalidRemoteException, TransportException, GitAPIException, IOException {
setProxy();
CloneCommand cmd = Git.cloneRepository()
.setURI(config.getRemoteUrl());
if (config.getLocalPath() != "") {
cmd.setDirectory(new File(config.getLocalPath()));
}
Git git = cmd.call();
// Set proxy setting to repository config.
StoredConfig gitConfig = git.getRepository().getConfig();
gitConfig.setString("remote", "origin", "proxy", config.getProxyAddress());
gitConfig.save();
git.getRepository().close();
}
示例2: isUserSetup
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
public static boolean isUserSetup (File root) {
Repository repository = getRepository(root);
boolean userExists = true;
if (repository != null) {
try {
StoredConfig config = repository.getConfig();
String name = config.getString("user", null, "name"); //NOI18N
String email = config.getString("user", null, "email"); //NOI18N
if (name == null || name.isEmpty() || email == null || email.isEmpty()) {
userExists = false;
}
} finally {
repository.close();
}
}
return userExists;
}
示例3: persistUser
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
public static void persistUser (File root, GitUser author) throws GitException {
Repository repository = getRepository(root);
if (repository != null) {
try {
StoredConfig config = repository.getConfig();
config.setString("user", null, "name", author.getName()); //NOI18N
config.setString("user", null, "email", author.getEmailAddress()); //NOI18N
try {
config.save();
FileUtil.refreshFor(new File(GitUtils.getGitFolderForRoot(root), "config"));
} catch (IOException ex) {
throw new GitException(ex);
}
} finally {
repository.close();
}
}
}
示例4: run
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
@Override
protected void run () throws GitException {
Repository repository = getRepository();
StoredConfig config = repository.getConfig();
config.unsetSection(ConfigConstants.CONFIG_REMOTE_SECTION, remote);
Set<String> subSections = config.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION);
for (String subSection : subSections) {
if (remote.equals(config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, subSection, ConfigConstants.CONFIG_KEY_REMOTE))) {
config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, subSection, ConfigConstants.CONFIG_KEY_REMOTE);
config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, subSection, ConfigConstants.CONFIG_KEY_MERGE);
}
}
try {
config.save();
} catch (IOException ex) {
throw new GitException(ex);
}
}
示例5: test199443_GlobalIgnoreFile
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
public void test199443_GlobalIgnoreFile () throws Exception {
File f = new File(new File(workDir, "nbproject"), "file");
f.getParentFile().mkdirs();
f.createNewFile();
File ignoreFile = new File(workDir.getParentFile(), "globalignore");
write(ignoreFile, ".DS_Store\n.svn\nnbproject\nnbproject/private\n");
Repository repo = getRepository(getLocalGitRepository());
StoredConfig cfg = repo.getConfig();
cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EXCLUDESFILE, ignoreFile.getAbsolutePath());
cfg.save();
GitClient client = getClient(workDir);
assertEquals(Status.STATUS_IGNORED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC());
// now since the file is already ignored, no ignore file should be modified
assertEquals(0, client.ignore(new File[] { f }, NULL_PROGRESS_MONITOR).length);
// on the other hand, if .git/info/exclude reverts the effect of global excludes file, ignored file should be modified
File dotGitIgnoreFile = new File(new File(repo.getDirectory(), "info"), "exclude");
dotGitIgnoreFile.getParentFile().mkdirs();
write(dotGitIgnoreFile, "!/nbproject/");
assertEquals(Status.STATUS_ADDED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC());
assertEquals(dotGitIgnoreFile, client.ignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]);
assertEquals(Status.STATUS_IGNORED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC());
}
示例6: test199443_GlobalIgnoreFileOverwrite
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
public void test199443_GlobalIgnoreFileOverwrite () throws Exception {
File f = new File(new File(workDir, "nbproject"), "file");
f.getParentFile().mkdirs();
f.createNewFile();
File ignoreFile = new File(workDir.getParentFile(), "globalignore");
Repository repo = getRepository(getLocalGitRepository());
StoredConfig cfg = repo.getConfig();
cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EXCLUDESFILE, ignoreFile.getAbsolutePath());
cfg.save();
write(ignoreFile, "!nbproject");
GitClient client = getClient(workDir);
assertEquals(new File(workDir, Constants.GITIGNORE_FILENAME), client.ignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]);
assertEquals("/nbproject/file", read(new File(workDir, Constants.GITIGNORE_FILENAME)));
}
示例7: testAddRemote
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
public void testAddRemote () throws Exception {
StoredConfig config = repository.getConfig();
assertEquals(0, config.getSubsections("remote").size());
GitClient client = getClient(workDir);
GitRemoteConfig remoteConfig = new GitRemoteConfig("origin",
Arrays.asList(new File(workDir.getParentFile(), "repo2").toURI().toString()),
Arrays.asList(new File(workDir.getParentFile(), "repo2").toURI().toString()),
Arrays.asList("+refs/heads/*:refs/remotes/origin/*"),
Arrays.asList("refs/remotes/origin/*:+refs/heads/*"));
client.setRemote(remoteConfig, NULL_PROGRESS_MONITOR);
config.load();
RemoteConfig cfg = new RemoteConfig(config, "origin");
assertEquals(Arrays.asList(new URIish(new File(workDir.getParentFile(), "repo2").toURI().toString())), cfg.getURIs());
assertEquals(Arrays.asList(new URIish(new File(workDir.getParentFile(), "repo2").toURI().toString())), cfg.getPushURIs());
assertEquals(Arrays.asList(new RefSpec("+refs/heads/*:refs/remotes/origin/*")), cfg.getFetchRefSpecs());
assertEquals(Arrays.asList(new RefSpec("refs/remotes/origin/*:+refs/heads/*")), cfg.getPushRefSpecs());
}
示例8: testMergeBranchNoHeadYet_196837
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
public void testMergeBranchNoHeadYet_196837 () throws Exception {
StoredConfig cfg = getRemoteRepository().getConfig();
cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE, false);
cfg.save();
File otherRepo = getRemoteRepository().getWorkTree();
File original = new File(otherRepo, "f");
GitClient clientOtherRepo = getClient(otherRepo);
write(original, "initial content");
clientOtherRepo.add(new File[] { original }, NULL_PROGRESS_MONITOR);
clientOtherRepo.commit(new File[] { original }, "initial commit", null, null, NULL_PROGRESS_MONITOR);
GitClient client = getClient(workDir);
Map<String, GitTransportUpdate> updates = client.fetch(otherRepo.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR);
GitMergeResult result = client.merge("origin/master", NULL_PROGRESS_MONITOR);
assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(Arrays.asList(new String[] { ObjectId.zeroId().getName(), updates.get("origin/master").getNewObjectId() }), Arrays.asList(result.getMergedCommits()));
}
示例9: testAddIgnoreExecutable
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
public void testAddIgnoreExecutable () throws Exception {
if (isWindows()) {
// no reason to test on windows
return;
}
File f = new File(workDir, "f");
write(f, "hi, i am executable");
f.setExecutable(true);
File[] roots = { f };
GitClient client = getClient(workDir);
StoredConfig config = repository.getConfig();
config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false);
config.save();
// add should not set executable bit in index
add(roots);
Map<File, GitStatus> statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, f, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false);
// index should differ from wt
config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true);
config.save();
statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, f, true, Status.STATUS_ADDED, Status.STATUS_MODIFIED, Status.STATUS_ADDED, false);
}
示例10: test199443_GlobalIgnoreFile
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
public void test199443_GlobalIgnoreFile () throws Exception {
File f = new File(new File(workDir, "nbproject"), "file");
f.getParentFile().mkdirs();
f.createNewFile();
File ignoreFile = new File(workDir.getParentFile(), "globalignore");
write(ignoreFile, "nbproject");
Repository repo = getRepository(getLocalGitRepository());
StoredConfig cfg = repo.getConfig();
cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EXCLUDESFILE, ignoreFile.getAbsolutePath());
cfg.save();
GitClient client = getClient(workDir);
assertEquals(Status.STATUS_IGNORED, client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f).getStatusIndexWC());
assertEquals(new File(workDir, Constants.GITIGNORE_FILENAME), client.unignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]);
write(new File(workDir, Constants.GITIGNORE_FILENAME), "/nbproject/file");
assertEquals(new File(workDir, Constants.GITIGNORE_FILENAME), client.unignore(new File[] { f }, NULL_PROGRESS_MONITOR)[0]);
assertEquals("!/nbproject/file", read(new File(workDir, Constants.GITIGNORE_FILENAME)));
}
示例11: doOK
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
/**
* Adds the remote as origin to the repository
*/
@Override
protected void doOK() {
super.doOK();
StoredConfig config;
try {
config = GitAccess.getInstance().getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
URIish uri = new URIish(remoteRepoTextField.getText());
remoteConfig.addURI(uri);
RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
remoteConfig.addFetchRefSpec(spec);
remoteConfig.update(config);
config.save();
} catch (NoRepositorySelected | URISyntaxException | IOException e) {
if (logger.isDebugEnabled()) {
logger.debug(e, e);
}
}
dispose();
}
示例12: testRemoteRepositoryHasNoCommitst
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
@Test(expected = MissingObjectException.class)
public void testRemoteRepositoryHasNoCommitst()
throws URISyntaxException, IOException, InvalidRemoteException, TransportException, GitAPIException, NoRepositorySelected {
gitAccess.setRepository(LOCAL_TEST_REPOSITPRY);
final StoredConfig config = gitAccess.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
URIish uri = new URIish(db2.getDirectory().toURI().toURL());
remoteConfig.addURI(uri);
remoteConfig.update(config);
config.save();
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
// throws missingObjectException
db2.resolve(gitAccess.getLastLocalCommit().getName() + "^{commit}");
}
示例13: testPushOK
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
@Test
public void testPushOK()
throws URISyntaxException, IOException, InvalidRemoteException, TransportException, GitAPIException, NoRepositorySelected {
gitAccess.setRepository(LOCAL_TEST_REPOSITPRY);
final StoredConfig config = gitAccess.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
URIish uri = new URIish(db2.getDirectory().toURI().toURL());
remoteConfig.addURI(uri);
remoteConfig.update(config);
config.save();
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
gitAccess.push("", "");
assertEquals(db1.resolve(gitAccess.getLastLocalCommit().getName() + "^{commit}"),
db2.resolve(gitAccess.getLastLocalCommit().getName() + "^{commit}"));
}
示例14: configureBranch
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
protected void configureBranch(Git git, String branch) {
// lets update the merge config
if (Strings.isNotBlank(branch)) {
StoredConfig config = git.getRepository().getConfig();
if (Strings.isNullOrBlank(config.getString("branch", branch, "remote")) || Strings.isNullOrBlank(config.getString("branch", branch, "merge"))) {
config.setString("branch", branch, "remote", getRemote());
config.setString("branch", branch, "merge", "refs/heads/" + branch);
try {
config.save();
} catch (IOException e) {
LOG.error("Failed to save the git configuration to " + basedir
+ " with branch " + branch + " on remote repo: " + remoteRepository + " due: " + e.getMessage() + ". This exception is ignored.", e);
}
}
}
}
示例15: clone
import org.eclipse.jgit.lib.StoredConfig; //导入依赖的package包/类
public static void clone(String url, File target) throws GitAPIException, IOException
{
System.out.println( "Starting clone of " + url + " to " + target );
Git result = Git.cloneRepository().setURI( url ).setDirectory( target ).call();
try
{
StoredConfig config = result.getRepository().getConfig();
config.setBoolean( "core", null, "autocrlf", autocrlf );
config.save();
System.out.println( "Cloned git repository " + url + " to " + target.getAbsolutePath() + ". Current HEAD: " + commitHash( result ) );
} finally
{
result.close();
}
}