List of usage examples for org.eclipse.jgit.lib Repository getConfig
@NonNull public abstract StoredConfig getConfig();
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.AgentVcsSupportTest.java
License:Apache License
@TestFor(issues = { "TW-42551", "TW-46857" }) public void should_set_remote_tracking_branch() throws Exception { AgentRunningBuild build = createRunningBuild(map(PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY, PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY_ALTERNATES)); myRoot = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(myMainRepo)) .withUseMirrors(true).build(); myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, "465ad9f630e451b9f2b782ffb09804c6a98c4bb9", myCheckoutDir, build, false); Repository r = new RepositoryBuilder().setWorkTree(myCheckoutDir).build(); then(new BranchConfig(r.getConfig(), "master").getRemoteTrackingBranch()) .isEqualTo("refs/remotes/origin/master"); //TW-46857//from w w w .j ava 2 s .co m myRoot = vcsRoot().withAgentGitPath(getGitPath()).withBranch("personal-branch2") .withFetchUrl(GitUtils.toURL(myMainRepo)).withUseMirrors(true).build(); myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, "3df61e6f11a5a9b919cb3f786a83fdd09f058617", myCheckoutDir, build, false); then(new BranchConfig(r.getConfig(), "personal-branch2").getRemoteTrackingBranch()) .isEqualTo("refs/remotes/origin/personal-branch2"); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.AgentVcsSupportTest.java
License:Apache License
public void old_cloned_repository_should_use_local_mirror() throws Exception { AgentRunningBuild buildBeforeUsingMirrors = createRunningBuild(false); myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, buildBeforeUsingMirrors, false); AgentRunningBuild buildWithMirrorsEnabled = createRunningBuild(true); myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, buildWithMirrorsEnabled, false); GitVcsRoot root = new GitVcsRoot(myBuilder.getMirrorManager(), myRoot); String localMirrorUrl = new URIish(root.getRepositoryDir().toURI().toASCIIString()).toString(); Repository r = new RepositoryBuilder().setWorkTree(myCheckoutDir).build(); assertEquals(root.getRepositoryFetchURL().toString(), r.getConfig().getString("url", localMirrorUrl, "insteadOf")); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.AgentVcsSupportTest.java
License:Apache License
public void stop_use_any_mirror_if_agent_property_changed_to_false() throws Exception { AgentRunningBuild build2 = createRunningBuild(false); GitVcsRoot root = new GitVcsRoot(myBuilder.getMirrorManager(), myRoot); myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, build2, false); //add some mirror Repository r = new RepositoryBuilder().setWorkTree(myCheckoutDir).build(); StoredConfig config = r.getConfig(); config.setString("url", "/some/path", "insteadOf", root.getRepositoryFetchURL().toString()); config.save();/* w ww . j a va 2 s .c o m*/ myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, build2, false); config = new RepositoryBuilder().setWorkTree(myCheckoutDir).build().getConfig(); assertTrue(config.getSubsections("url").isEmpty()); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.HttpAuthTest.java
License:Apache License
@RequiredGitVersion(min = "2.9.0") @TestFor(issues = { "TW-46668", "TW-45991", "TW-46391" }) public void disable_credential_helpers(@NotNull GitExec git) throws Exception { //Test checks that we disable credential helpers configured on machine File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.1"), "repo.git"); Random r = new Random(); final String user = "user"; final String password = String.valueOf(r.nextInt(100)); myServer = new GitHttpServer(git.getPath(), repo); myServer.setCredentials(user, password); myServer.start();//from w w w .j a va 2 s .com VcsRootImpl root = vcsRoot().withFetchUrl(myServer.getRepoUrl()) .withAuthMethod(AuthenticationMethod.PASSWORD).withUsername(user).withPassword(password) .withBranch("master").build(); File buildDir = myTempFiles.createTempDir(); AgentRunningBuild build = runningBuild().sharedEnvVariable(Constants.TEAMCITY_AGENT_GIT_PATH, git.getPath()) .sharedConfigParams(PluginConfigImpl.USE_ALTERNATES, "true").build(); //run first build to initialize mirror: Checkout checkout = new Checkout(root, "add81050184d3c818560bdd8839f50024c188586", buildDir, build); checkout.run(TimeUnit.SECONDS.toMillis(10)); assertTrue(checkout.success()); //update remote repo with new commits: FileUtil.delete(repo); copyRepository(dataFile("repo_for_fetch.2"), repo); //configure hanging credential helper for mirror: File mirrorDir = myBuilder.getMirrorManager() .getMirrorDir(myServer.getRepoUrl().replaceAll("http://", "http://" + user + "@")); Repository mirror = new RepositoryBuilder().setGitDir(mirrorDir).build(); StoredConfig config = mirror.getConfig(); config.setString("credential", null, "helper", createHangingCredProvider(100).getCanonicalPath()); config.save(); //run build requiring a mirror update, hanging helper should be disabled and checkout should finish successfully checkout = new Checkout(root, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", buildDir, build); checkout.run(TimeUnit.SECONDS.toMillis(10)); assertTrue(checkout.success()); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.RepositoryManagerTest.java
License:Apache License
public void should_create_repository_if_remote_is_not_specified() throws Exception { RepositoryManager repositoryManager = getRepositoryManager(); File customDir = myTempFiles.createTempDir(); URIish url = new URIish("git://some.org/repo.git"); Repository r = repositoryManager.openRepository(customDir, url); r.getConfig().unset("teamcity", null, "remote"); Repository r2 = repositoryManager.openRepository(customDir, url); then(r2.getConfig().getString("teamcity", null, "remote")).isEqualTo(url.toString()); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.RepositoryManagerTest.java
License:Apache License
public void get_repository_in_dir_with_existing_config_without_teamcity_remote() throws Exception { File customDir = myTempFiles.createTempDir(); Repository r = new RepositoryBuilder().setGitDir(customDir).setBare().build(); assertNull(r.getConfig().getString("teamcity", null, "remote")); RepositoryManager repositoryManager = getRepositoryManager(); Repository r2 = repositoryManager.openRepository(customDir, new URIish("git://some.org/repo.git")); assertEquals(customDir, r2.getDirectory()); assertEquals("git://some.org/repo.git", r2.getConfig().getString("teamcity", null, "remote")); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.SubmoduleTest.java
License:Apache License
/** * Test loading mapping for submodules// w w w . ja v a 2 s .com * * @throws IOException if there is IO problem */ @Test public void testSubmoduleMapping() throws Exception { File masterRep = dataFile("repo.git"); Repository r = new RepositoryBuilder().setGitDir(masterRep).build(); try { SubmodulesConfig s = new SubmodulesConfig(r.getConfig(), new BlobBasedConfig(null, r, r.resolve(GitUtils.versionRevision(GitVcsSupportTest.SUBMODULE_ADDED_VERSION)), ".gitmodules")); assertTrue(s.isSubmodulePrefix("")); assertFalse(s.isSubmodulePrefix("submodule")); Submodule m = s.findSubmodule("submodule"); assertEquals(m.getName(), "submodule"); assertEquals(m.getPath(), "submodule"); assertEquals(m.getUrl(), "../submodule.git"); } finally { r.close(); } }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.SubmoduleTest.java
License:Apache License
/** * Test loading mapping for submodules//from w ww .j a v a 2s .c om * * @throws IOException if there is IO problem */ @Test public void testSubmoduleMultiEntryMapping() throws Exception { File masterRep = dataFile("repo.git"); File submodulesFile = dataFile("content", "dotgitmodules"); Repository r = new RepositoryBuilder().setGitDir(masterRep).build(); try { FileBasedConfig config = new FileBasedConfig(null, submodulesFile, FS.DETECTED); config.load(); SubmodulesConfig s = new SubmodulesConfig(r.getConfig(), config); assertTrue(s.isSubmodulePrefix("")); assertFalse(s.isSubmodulePrefix("c/")); Submodule m = s.findSubmodule("b"); assertEquals(m.getName(), "b"); assertEquals(m.getPath(), "b"); assertEquals(m.getUrl(), "git@gitrep:/git/b.git"); m = s.findSubmodule("c/D"); assertEquals(m.getName(), "c/D"); assertEquals(m.getPath(), "c/D"); assertEquals(m.getUrl(), "git@gitrep:/git/d.git"); } finally { r.close(); } }
From source file:me.cmoz.gradle.snapshot.GitSCMCommand.java
License:Apache License
@Override @SneakyThrows(IOException.class) public Commit getLatestCommit(@NonNull final String dateFormat) { if (repoDir == null) { throw new IllegalStateException("'.git' folder could not be found."); }// ww w. j a va 2 s . c o m final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final Repository repo = builder.setGitDir(repoDir).readEnvironment().build(); final StoredConfig conf = repo.getConfig(); int abbrev = Commit.ABBREV_LENGTH; if (conf != null) { abbrev = conf.getInt("core", "abbrev", abbrev); } final SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); final Ref HEAD = repo.getRef(Constants.HEAD); if (HEAD.getObjectId() == null) { throw new RuntimeException("Could not find any commits from HEAD ref."); } final RevWalk revWalk = new RevWalk(repo); if (HEAD.getObjectId() == null) { throw new RuntimeException("Could not find any commits from HEAD ref."); } final RevCommit revCommit = revWalk.parseCommit(HEAD.getObjectId()); revWalk.markStart(revCommit); try { // git commit time in sec and java datetime is in ms final Date commitTime = new Date(revCommit.getCommitTime() * 1000L); final PersonIdent ident = revCommit.getAuthorIdent(); final UserConfig userConf = conf.get(UserConfig.KEY); return Commit.builder().buildTime(sdf.format(new Date())).buildAuthorName(userConf.getAuthorName()) .buildAuthorEmail(userConf.getAuthorEmail()).branchName(repo.getBranch()) .commitId(revCommit.getName()).commitTime(sdf.format(commitTime)) .commitUserName(ident.getName()).commitUserEmail(ident.getEmailAddress()) .commitMessage(revCommit.getFullMessage().trim()).build(); } finally { revWalk.dispose(); repo.close(); } }
From source file:net.mobid.codetraq.runnables.GitChecker.java
License:Open Source License
private boolean isMasterBranchDefined(Repository r) { if (r.getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, _server.getServerBranch(), ConfigConstants.CONFIG_KEY_REMOTE) == null) { return false; }/*from ww w . j a v a 2 s . co m*/ return true; }