Java Code Examples for org.eclipse.jgit.lib.Config#fromText()
The following examples show how to use
org.eclipse.jgit.lib.Config#fromText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LegacyCompatibleGitAPIImplTest.java From git-client-plugin with MIT License | 6 votes |
@Test @Deprecated public void testCloneRemoteConfig() throws URISyntaxException, InterruptedException, IOException, ConfigInvalidException { if (gitImpl.equals("jgit")) { return; } Config config = new Config(); /* Use local git-client-plugin repository as source for clone test */ String remoteName = "localCopy"; String localRepoPath = (new File(".")).getCanonicalPath().replace("\\", "/"); String configText = "[remote \"" + remoteName + "\"]\n" + "url = " + localRepoPath + "\n" + "fetch = +refs/heads/*:refs/remotes/" + remoteName + "/*\n"; config.fromText(configText); RemoteConfig remoteConfig = new RemoteConfig(config, remoteName); List<URIish> list = remoteConfig.getURIs(); git.clone(remoteConfig); File[] files = git.workspace.listFiles(); assertEquals(files.length + "files in " + Arrays.toString(files), 1, files.length); assertEquals("Wrong file name", ".git", files[0].getName()); }
Example 2
Source File: GitAPITestCase.java From git-client-plugin with MIT License | 5 votes |
@Deprecated public void test_push_deprecated_signature() throws Exception { /* Make working repo a remote of the bare repo */ w.init(); w.commitEmpty("init"); ObjectId workHead = w.head(); /* Create a bare repo */ WorkingArea bare = new WorkingArea(); bare.init(true); /* Set working repo origin to point to bare */ w.git.setRemoteUrl("origin", bare.repoPath()); assertEquals("Wrong remote URL", w.git.getRemoteUrl("origin"), bare.repoPath()); /* Push to bare repo */ w.git.push("origin", "master"); /* JGitAPIImpl revParse fails unexpectedly when used here */ ObjectId bareHead = w.git instanceof CliGitAPIImpl ? bare.head() : ObjectId.fromString(bare.launchCommand("git", "rev-parse", "master").substring(0, 40)); assertEquals("Heads don't match", workHead, bareHead); assertEquals("Heads don't match", w.git.getHeadRev(w.repoPath(), "master"), bare.git.getHeadRev(bare.repoPath(), "master")); /* Commit a new file */ w.touch("file1"); w.git.add("file1"); w.git.commit("commit1"); /* Push commit to the bare repo */ Config config = new Config(); config.fromText(w.contentOf(".git/config")); RemoteConfig origin = new RemoteConfig(config, "origin"); w.igit().push(origin, "master"); /* JGitAPIImpl revParse fails unexpectedly when used here */ ObjectId workHead2 = w.git instanceof CliGitAPIImpl ? w.head() : ObjectId.fromString(w.launchCommand("git", "rev-parse", "master").substring(0, 40)); ObjectId bareHead2 = w.git instanceof CliGitAPIImpl ? bare.head() : ObjectId.fromString(bare.launchCommand("git", "rev-parse", "master").substring(0, 40)); assertEquals("Working SHA1 != bare SHA1", workHead2, bareHead2); assertEquals("Working SHA1 != bare SHA1", w.git.getHeadRev(w.repoPath(), "master"), bare.git.getHeadRev(bare.repoPath(), "master")); }
Example 3
Source File: RepoRelativePath.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Tries to obtain repository name from the provided directory by reading git config in * {@code currendDir/.git/config} * <p> * Git clone folder name might be different from git repository name * * @return string with repo name or {@code null} */ private static String getRepoName(File currentDir) { if (currentDir == null) { return "NO_REPO"; } File gitFolder = new File(currentDir, ".git"); if (!gitFolder.isDirectory()) { if (LOGGER.isDebugEnabled()) LOGGER.debug("No '.git' folder at " + currentDir.getAbsolutePath()); return null; } File config = new File(gitFolder, "config"); if (!config.isFile()) { if (LOGGER.isDebugEnabled()) LOGGER.debug("No 'config' file at " + gitFolder.getAbsolutePath()); return null; } try { String configStr = Files.asCharSource(config, Charset.defaultCharset()).read(); Config cfg = new Config(); cfg.fromText(configStr); String originURL = cfg.getString("remote", "origin", "url"); if (originURL != null && !originURL.isEmpty()) { int lastSlash = originURL.lastIndexOf('/'); String repoName = null; if (lastSlash >= 0) { repoName = originURL.substring(lastSlash + 1); } else { repoName = originURL; } if (repoName.endsWith(".git")) { repoName = repoName.substring(0, repoName.length() - 4); } return repoName; } } catch (ConfigInvalidException | IOException e) { LOGGER.warn("Cannot read git config at " + config.getAbsolutePath(), e); } return null; }