Java Code Examples for org.eclipse.jgit.lib.StoredConfig#save()
The following examples show how to use
org.eclipse.jgit.lib.StoredConfig#save() .
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: RestGitBackupService.java From EDDI with Apache License 2.0 | 6 votes |
@Override public Response gitInit(String botId) { try { deleteFileIfExists(Paths.get(tmpPath + botId)); Path gitPath = Files.createDirectories(Paths.get(tmpPath + botId)); Git git = Git.cloneRepository() .setBranch(gitBranch) .setURI(gitUrl) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitUsername, gitPassword)) .setDirectory(gitPath.toFile()) .call(); StoredConfig config = git.getRepository().getConfig(); config.setString( CONFIG_BRANCH_SECTION, "local-branch", "remote", gitBranch); config.setString( CONFIG_BRANCH_SECTION, "local-branch", "merge", "refs/heads/" + gitBranch ); config.save(); } catch (IOException | GitAPIException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } return Response.accepted().build(); }
Example 2
Source File: GitSubmoduleHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
public static void removeSubmodule(Repository db, Repository parentRepo, String pathToSubmodule) throws Exception { pathToSubmodule = pathToSubmodule.replace("\\", "/"); StoredConfig gitSubmodulesConfig = getGitSubmodulesConfig(parentRepo); gitSubmodulesConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule); gitSubmodulesConfig.save(); StoredConfig repositoryConfig = parentRepo.getConfig(); repositoryConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule); repositoryConfig.save(); Git git = Git.wrap(parentRepo); git.add().addFilepattern(DOT_GIT_MODULES).call(); RmCommand rm = git.rm().addFilepattern(pathToSubmodule); if (gitSubmodulesConfig.getSections().size() == 0) { rm.addFilepattern(DOT_GIT_MODULES); } rm.call(); FileUtils.delete(db.getWorkTree(), FileUtils.RECURSIVE); FileUtils.delete(db.getDirectory(), FileUtils.RECURSIVE); }
Example 3
Source File: AbstractGitTest.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
void setOriginOnProjectToTmp(File origin, File project, boolean push) throws GitAPIException, IOException, URISyntaxException { try (Git git = openGitProject(project)) { RemoteRemoveCommand remove = git.remoteRemove(); remove.setName("origin"); remove.call(); RemoteSetUrlCommand command = git.remoteSetUrl(); command.setUri(new URIish(origin.toURI().toURL())); command.setName("origin"); command.setPush(push); command.call(); StoredConfig config = git.getRepository().getConfig(); RemoteConfig originConfig = new RemoteConfig(config, "origin"); originConfig .addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); originConfig.update(config); config.save(); } }
Example 4
Source File: IgnoreTest.java From netbeans with Apache License 2.0 | 6 votes |
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()); }
Example 5
Source File: GitCloneTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testGetCloneAndPull() throws Exception { // see bug 339254 createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String workspaceId = getWorkspaceId(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null); String contentLocation = clone(workspaceId, project).getString(ProtocolConstants.KEY_CONTENT_LOCATION); JSONArray clonesArray = listClones(workspaceId, null); assertEquals(1, clonesArray.length()); Repository r = getRepositoryForContentLocation(contentLocation); // overwrite user settings, do not rebase when pulling, see bug 372489 StoredConfig cfg = r.getConfig(); cfg.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_REBASE, false); cfg.save(); // TODO: replace with RESTful API when ready, see bug 339114 Git git = Git.wrap(r); PullResult pullResult = git.pull().call(); assertEquals(pullResult.getMergeResult().getMergeStatus(), MergeStatus.ALREADY_UP_TO_DATE); assertEquals(RepositoryState.SAFE, git.getRepository().getRepositoryState()); }
Example 6
Source File: GitLabIT.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private String initGitLabProject(String url, boolean addFeatureBranch) throws GitAPIException, IOException { // Setup git repository Git.init().setDirectory(tmp.getRoot()).call(); Git git = Git.open(tmp.getRoot()); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", url); config.save(); // Setup remote master branch tmp.newFile("test"); git.add().addFilepattern("test"); RevCommit commit = git.commit().setMessage("test").call(); git.push() .setRemote("origin").add("master") .setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitlab.getUsername(), gitlab.getPassword())) .call(); if (addFeatureBranch) { // Setup remote feature branch git.checkout().setName("feature").setCreateBranch(true).call(); tmp.newFile("feature"); commit = git.commit().setMessage("feature").call(); git.push().setRemote("origin").add("feature").setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitlab.getUsername(), gitlab.getPassword())) .call(); } return commit.getName(); }
Example 7
Source File: AddTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testAddKeepExecutableInIndex () 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); 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); StoredConfig config = repository.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); // add should not overwrite executable bit in index f.setExecutable(false); add(roots); 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); }
Example 8
Source File: GitMigrator.java From rtc2gitcli with MIT License | 5 votes |
private void initConfig() throws IOException { StoredConfig config = git.getRepository().getConfig(); config.setBoolean("core", null, "ignoreCase", false); config.setString("core", null, "autocrlf", File.separatorChar == '/' ? "input" : "true"); config.setBoolean("http", null, "sslverify", false); config.setString("push", null, "default", "simple"); fillConfigFromProperties(config); config.save(); }
Example 9
Source File: StatusTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testIgnoreExecutable () throws Exception { if (isWindows()) { // no reason to test on win return; } File f = new File(workDir, "f"); write(f, "hi, i am executable"); f.setExecutable(true); File[] roots = { f }; add(roots); commit(roots); GitClient client = getClient(workDir); Map<File, GitStatus> statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); f.setExecutable(false); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); StoredConfig config = repository.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true); config.save(); add(roots); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); add(roots); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); }
Example 10
Source File: GetRemotesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testGetRemotes () throws Exception { GitClient client = getClient(workDir); StoredConfig cfg = repository.getConfig(); RemoteConfig remoteConfig = new RemoteConfig(cfg, "origin"); Map<String, GitRemoteConfig> remotes = client.getRemotes(NULL_PROGRESS_MONITOR); assertEquals(0, remotes.size()); remoteConfig.update(cfg); cfg.save(); remotes = client.getRemotes(NULL_PROGRESS_MONITOR); assertEquals(0, remotes.size()); remoteConfig.addURI(new URIish("file:///home/repository")); remoteConfig.addURI(new URIish("file:///home/repository2")); remoteConfig.addPushURI(new URIish("file:///home/repository")); remoteConfig.addPushURI(new URIish("file:///home/repository3")); remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/master:refs/remotes/origin/my-master")); remoteConfig.addPushRefSpec(new RefSpec("refs/remotes/origin/*:refs/heads/*")); remoteConfig.update(cfg); cfg.save(); remotes = client.getRemotes(NULL_PROGRESS_MONITOR); assertEquals(1, remotes.size()); assertEquals("origin", remotes.get("origin").getRemoteName()); assertEquals(Arrays.asList(new String[] { "file:///home/repository", "file:///home/repository2" }), remotes.get("origin").getUris()); assertEquals(Arrays.asList(new String[] { "file:///home/repository", "file:///home/repository3" }), remotes.get("origin").getPushUris()); assertEquals(Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*", "+refs/heads/master:refs/remotes/origin/my-master" }), remotes.get("origin").getFetchRefSpecs()); assertEquals(Arrays.asList(new String[] { "refs/remotes/origin/*:refs/heads/*" }), remotes.get("origin").getPushRefSpecs()); GitRemoteConfig remote = client.getRemote("origin", NULL_PROGRESS_MONITOR); assertEquals("origin", remote.getRemoteName()); assertEquals(Arrays.asList(new String[] { "file:///home/repository", "file:///home/repository2" }), remote.getUris()); assertEquals(Arrays.asList(new String[] { "file:///home/repository", "file:///home/repository3" }), remote.getPushUris()); assertEquals(Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*", "+refs/heads/master:refs/remotes/origin/my-master" }), remote.getFetchRefSpecs()); assertEquals(Arrays.asList(new String[] { "refs/remotes/origin/*:refs/heads/*" }), remote.getPushRefSpecs()); }
Example 11
Source File: XacmlAdminUI.java From XACML with MIT License | 5 votes |
/** * Initializes a user's git repository. * * * @param workspacePath * @param userId * @param email * @return * @throws IOException * @throws InvalidRemoteException * @throws TransportException * @throws GitAPIException */ private static Path initializeUserRepository(Path workspacePath, String userId, URI email) throws IOException, InvalidRemoteException, TransportException, GitAPIException { Path gitPath = null; // // Initialize the User's Git repository // if (Files.notExists(workspacePath)) { logger.info("Creating user workspace: " + workspacePath.toAbsolutePath().toString()); // // Create our user's directory // Files.createDirectory(workspacePath); } gitPath = Paths.get(workspacePath.toString(), XacmlAdminUI.repositoryPath.getFileName().toString()); if (Files.notExists(gitPath)) { // // It doesn't exist yet, so Clone it and check it out // logger.info("Cloning user git directory: " + gitPath.toAbsolutePath().toString()); Git.cloneRepository().setURI(XacmlAdminUI.repositoryPath.toUri().toString()) .setDirectory(gitPath.toFile()) .setNoCheckout(false) .call(); // // Set userid // Git git = Git.open(gitPath.toFile()); StoredConfig config = git.getRepository().getConfig(); config.setString("user", null, "name", userId); if (email != null && email.getPath() != null) { config.setString("user", null, "email", email.toString()); } config.save(); } return gitPath; }
Example 12
Source File: GitRelatedTest.java From multi-module-maven-release-plugin with MIT License | 5 votes |
@Test public void ifThereIsNoRemoteButTheScmDetailsArePresentThenThisIsUsed() throws GitAPIException, IOException, InterruptedException { TestProject testProject = TestProject.moduleWithScmTag(); StoredConfig config = testProject.local.getRepository().getConfig(); config.unsetSection("remote", "origin"); config.save(); testProject.mvnRelease("1"); }
Example 13
Source File: LocalGitRepoTest.java From multi-module-maven-release-plugin with MIT License | 5 votes |
@Test public void usesThePassedInScmUrlToFindRemote() throws Exception { String remote = scmUrlToRemote(dirToGitScmReference(project.originDir)); LocalGitRepo repo = new LocalGitRepo(project.local, new RemoteTagFetcher(project.local, remote, null), new LocalTagPusher(project.local)); tag(project.origin, "some-tag"); StoredConfig config = project.local.getRepository().getConfig(); config.unsetSection("remote", "origin"); config.save(); assertThat(repo.tagsFrom(tags("blah", "some-tag")), equalTo(asList("some-tag"))); }
Example 14
Source File: SetUpstreamBranchCommand.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void run () throws GitException { Repository repository = getRepository(); try { Ref ref = repository.findRef(trackedBranchName); if (ref == null) { throw new GitException(MessageFormat.format(Utils.getBundle(SetUpstreamBranchCommand.class) .getString("MSG_Error_UpdateTracking_InvalidReference"), trackedBranchName)); //NOI18N) } String remote = null; String branchName = ref.getName(); StoredConfig config = repository.getConfig(); if (branchName.startsWith(Constants.R_REMOTES)) { String[] elements = branchName.split("/", 4); remote = elements[2]; if (config.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION).contains(remote)) { branchName = Constants.R_HEADS + elements[3]; setupRebaseFlag(repository); } else { // remote not yet set remote = null; } } if (remote == null) { remote = "."; //NOI18N } config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_REMOTE, remote); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_MERGE, branchName); config.save(); } catch (IOException ex) { throw new GitException(ex); } ListBranchCommand branchCmd = new ListBranchCommand(repository, getClassFactory(), false, new DelegatingGitProgressMonitor(monitor)); branchCmd.run(); Map<String, GitBranch> branches = branchCmd.getBranches(); branch = branches.get(localBranchName); }
Example 15
Source File: CreateBranchCommand.java From netbeans with Apache License 2.0 | 5 votes |
private void setupRebaseFlag (Repository repository) throws IOException { Ref baseRef = repository.findRef(revision); if (baseRef != null && baseRef.getName().startsWith(Constants.R_REMOTES)) { StoredConfig config = repository.getConfig(); String autosetupRebase = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE); boolean rebase = ConfigConstants.CONFIG_KEY_ALWAYS.equals(autosetupRebase) || ConfigConstants.CONFIG_KEY_REMOTE.equals(autosetupRebase); if (rebase && !config.getNames(ConfigConstants.CONFIG_BRANCH_SECTION, branchName).isEmpty()) { config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, rebase); config.save(); } } }
Example 16
Source File: GitClientTest.java From git-client-plugin with MIT License | 5 votes |
@Test public void testAutocreateFailsOnMultipleMatchingOrigins() throws Exception { File repoRootTemp = tempFolder.newFolder(); GitClient gitClientTemp = Git.with(TaskListener.NULL, new EnvVars()).in(repoRootTemp).using(gitImplName).getClient(); gitClientTemp.init(); FilePath gitClientFilePath = gitClientTemp.getWorkTree(); FilePath gitClientTempFile = gitClientFilePath.createTextTempFile("aPre", ".txt", "file contents"); gitClientTemp.add("."); gitClientTemp.commit("Added " + gitClientTempFile.toURI().toString()); gitClient.clone_().url("file://" + repoRootTemp.getPath()).execute(); final URIish remote = new URIish(Constants.DEFAULT_REMOTE_NAME); try ( // add second remote FileRepository repo = new FileRepository(new File(repoRoot, ".git"))) { StoredConfig config = repo.getConfig(); config.setString("remote", "upstream", "url", "file://" + repoRootTemp.getPath()); config.setString("remote", "upstream", "fetch", "+refs/heads/*:refs/remotes/upstream/*"); config.save(); } // fill both remote branches List<RefSpec> refspecs = Collections.singletonList(new RefSpec( "refs/heads/*:refs/remotes/origin/*")); gitClient.fetch_().from(remote, refspecs).execute(); refspecs = Collections.singletonList(new RefSpec( "refs/heads/*:refs/remotes/upstream/*")); gitClient.fetch_().from(remote, refspecs).execute(); // checkout will fail try { gitClient.checkout().ref(Constants.MASTER).execute(); } catch (GitException e) { // expected Set<String> refNames = gitClient.getRefNames("refs/heads/"); assertFalse("RefNames will not contain master", refNames.contains("refs/heads/master")); } }
Example 17
Source File: GitRepository.java From centraldogma with Apache License 2.0 | 4 votes |
/** * Creates a new Git-backed repository. * * @param repoDir the location of this repository * @param format the repository format * @param repositoryWorker the {@link Executor} which will perform the blocking repository operations * @param creationTimeMillis the creation time * @param author the user who initiated the creation of this repository * * @throws StorageException if failed to create a new repository */ GitRepository(Project parent, File repoDir, GitRepositoryFormat format, Executor repositoryWorker, long creationTimeMillis, Author author, @Nullable RepositoryCache cache) { this.parent = requireNonNull(parent, "parent"); name = requireNonNull(repoDir, "repoDir").getName(); this.repositoryWorker = requireNonNull(repositoryWorker, "repositoryWorker"); this.format = requireNonNull(format, "format"); this.cache = cache; requireNonNull(author, "author"); final RepositoryBuilder repositoryBuilder = new RepositoryBuilder().setGitDir(repoDir).setBare(); boolean success = false; try { // Create an empty repository with format version 0 first. try (org.eclipse.jgit.lib.Repository initRepo = repositoryBuilder.build()) { if (exist(repoDir)) { throw new StorageException( "failed to create a repository at: " + repoDir + " (exists already)"); } initRepo.create(true); final StoredConfig config = initRepo.getConfig(); if (format == GitRepositoryFormat.V1) { // Update the repository settings to upgrade to format version 1 and reftree. config.setInt(CONFIG_CORE_SECTION, null, CONFIG_KEY_REPO_FORMAT_VERSION, 1); } // Disable hidden files, symlinks and file modes we do not use. config.setEnum(CONFIG_CORE_SECTION, null, CONFIG_KEY_HIDEDOTFILES, HideDotFiles.FALSE); config.setBoolean(CONFIG_CORE_SECTION, null, CONFIG_KEY_SYMLINKS, false); config.setBoolean(CONFIG_CORE_SECTION, null, CONFIG_KEY_FILEMODE, false); // Disable GPG signing. config.setBoolean(CONFIG_COMMIT_SECTION, null, CONFIG_KEY_GPGSIGN, false); // Set the diff algorithm. config.setString(CONFIG_DIFF_SECTION, null, CONFIG_KEY_ALGORITHM, "histogram"); // Disable rename detection which we do not use. config.setBoolean(CONFIG_DIFF_SECTION, null, CONFIG_KEY_RENAMES, false); config.save(); } // Re-open the repository with the updated settings and format version. jGitRepository = new RepositoryBuilder().setGitDir(repoDir).build(); // Initialize the master branch. final RefUpdate head = jGitRepository.updateRef(Constants.HEAD); head.disableRefLog(); head.link(Constants.R_HEADS + Constants.MASTER); // Initialize the commit ID database. commitIdDatabase = new CommitIdDatabase(jGitRepository); // Insert the initial commit into the master branch. commit0(null, Revision.INIT, creationTimeMillis, author, "Create a new repository", "", Markup.PLAINTEXT, Collections.emptyList(), true); headRevision = Revision.INIT; success = true; } catch (IOException e) { throw new StorageException("failed to create a repository at: " + repoDir, e); } finally { if (!success) { internalClose(); // Failed to create a repository. Remove any cruft so that it is not loaded on the next run. deleteCruft(repoDir); } } }
Example 18
Source File: GitResetTest.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test @Ignore("see bug 339397") public void testResetAutocrlfTrue() throws Exception { // "git config core.autocrlf true" Git git = Git.wrap(db); StoredConfig config = git.getRepository().getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, Boolean.TRUE); config.save(); createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String projectName = getMethodName().concat("Project"); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); String projectId = project.getString(ProtocolConstants.KEY_ID); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); String gitCommitUri = gitSection.getString(GitConstants.KEY_COMMIT); // CRLF JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "f" + "\r\n" + "older"); addFile(testTxt); // commit WebRequest request = GitCommitTest.getPostGitCommitRequest(gitCommitUri, "added new line - crlf", false); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // assert there is nothing to commit assertStatus(StatusResult.CLEAN, gitStatusUri); // create new file String fileName = "new.txt"; // TODO: don't create URIs out of thin air request = getPostFilesRequest(projectId + "/", getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject file = new JSONObject(response.getText()); String location = file.optString(ProtocolConstants.KEY_LOCATION, null); assertNotNull(location); // LF JSONObject newTxt = getChild(project, "new.txt"); modifyFile(newTxt, "i'm" + "\n" + "new"); // "git add ." request = GitAddTest.getPutGitIndexRequest(gitIndexUri /* stage all */); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // reset request = getPostGitIndexRequest(gitIndexUri /* reset all */, ResetType.MIXED); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertStatus(new StatusResult().setUntracked(1), gitStatusUri); }
Example 19
Source File: PushTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testPushUpdateInRemotes () throws Exception { String remoteUri = getRemoteRepository().getWorkTree().toURI().toString(); assertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size()); File f = new File(workDir, "f"); add(f); String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); Map<String, GitTransportUpdate> updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); Map<String, GitBranch> remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); assertEquals(id, remoteBranches.get("master").getId()); assertEquals(1, updates.size()); assertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); getClient(workDir).pull(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/remotes/origin/master" }), "master", NULL_PROGRESS_MONITOR); Map<String, GitBranch> branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertEquals(id, branches.get("origin/master").getId()); // modification write(f, "huhu"); add(f); String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); GitPushResult result = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR); updates = result.getRemoteRepositoryUpdates(); Map<String, GitTransportUpdate> localUpdates = result.getLocalRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); // not yet updated, tracking branches has not been set assertEquals(0, localUpdates.size()); assertEquals(id, branches.get("origin/master").getId()); // another modification write(f, "huhu2"); add(f); newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); result = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Arrays.asList(new String[] { "refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR); updates = result.getRemoteRepositoryUpdates(); localUpdates = result.getLocalRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertEquals(1, localUpdates.size()); assertUpdate(localUpdates.get("master"), "origin/master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, EnumSet.of(GitRefUpdateResult.FAST_FORWARD, GitRefUpdateResult.FORCED)); assertEquals(newid, branches.get("origin/master").getId()); //let's set tracking branch StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", ConfigConstants.CONFIG_KEY_URL, new URIish(remoteUri).toString()); cfg.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "fetch", "+refs/heads/master:refs/remotes/origin/master"); cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE, "origin"); cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/master"); cfg.save(); // what about now??? write(f, "huhu3"); add(f); id = newid; newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); result = getClient(workDir).push("origin", Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.<String>emptyList(), NULL_PROGRESS_MONITOR); updates = result.getRemoteRepositoryUpdates(); localUpdates = result.getLocalRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertUpdate(updates.get("master"), "master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertEquals(1, localUpdates.size()); assertUpdate(localUpdates.get("master"), "origin/master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, EnumSet.of(GitRefUpdateResult.FAST_FORWARD, GitRefUpdateResult.FORCED)); assertEquals(newid, branches.get("origin/master").getId()); // and what about adding a new branch, does it show among remotes? result = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/newbranch" }), Arrays.asList(new String[] { "refs/heads/newbranch:refs/remotes/origin/newbranch" }), NULL_PROGRESS_MONITOR); updates = result.getRemoteRepositoryUpdates(); localUpdates = result.getLocalRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(2, remoteBranches.size()); branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(3, branches.size()); assertEquals(1, localUpdates.size()); assertUpdate(localUpdates.get("newbranch"), "origin/newbranch", "newbranch", newid, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.NEW); assertEquals(newid, branches.get("origin/newbranch").getId()); }
Example 20
Source File: DifferentFilesHttpFetchBasicAuthTest.java From gitflow-incremental-builder with MIT License | 4 votes |
public void unsetCredentialHelper() throws IOException { StoredConfig config = localRepoMock.getGit().getRepository().getConfig(); config.unset("credential", null, "helper"); config.save(); }