org.eclipse.jgit.lib.Constants Java Examples
The following examples show how to use
org.eclipse.jgit.lib.Constants.
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: BitmappedReachabilityChecker.java From onedev with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public final boolean include(RevWalk walker, RevCommit cmit) { Bitmap commitBitmap; if (reached.contains(cmit)) { // already seen or included dontFollow(cmit); return false; } if ((commitBitmap = repoBitmaps.getBitmap(cmit)) != null) { reached.or(commitBitmap); // Emit the commit because there are new contents in the bitmap // but don't follow parents (they are already in the bitmap) dontFollow(cmit); return true; } // No bitmaps, keep going reached.addObject(cmit, Constants.OBJ_COMMIT); return true; }
Example #2
Source File: RevisionSelector.java From onedev with MIT License | 6 votes |
public RevisionSelector(String id, IModel<Project> projectModel, @Nullable String revision, boolean canCreateRef) { super(id); Preconditions.checkArgument(revision!=null || !canCreateRef); this.projectModel = projectModel; this.revision = revision; if (canCreateRef) { Project project = projectModel.getObject(); canCreateBranch = SecurityUtils.canCreateBranch(project, Constants.R_HEADS); canCreateTag = SecurityUtils.canCreateTag(project, Constants.R_TAGS); } else { canCreateBranch = false; canCreateTag = false; } if (revision != null) { Ref ref = projectModel.getObject().getRef(revision); branchesActive = ref == null || GitUtils.ref2tag(ref.getName()) == null; } else { branchesActive = true; } refs = findRefs(); }
Example #3
Source File: GitRemoteTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testGetOrigin() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); String gitRemoteUri = clone.getString(GitConstants.KEY_REMOTE); JSONObject remoteBranch = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER); assertNotNull(remoteBranch); // get project/folder metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject folder = new JSONObject(response.getText()); // check if Git locations are in place JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT); assertEquals(gitRemoteUri, gitSection.getString(GitConstants.KEY_REMOTE)); } }
Example #4
Source File: Project.java From onedev with MIT License | 6 votes |
public RevCommit getLastCommit() { if (lastCommitHolder == null) { RevCommit lastCommit = null; try { for (Ref ref: getRepository().getRefDatabase().getRefsByPrefix(Constants.R_HEADS)) { RevCommit commit = getRevCommit(ref.getObjectId(), false); if (commit != null) { if (lastCommit != null) { if (commit.getCommitTime() > lastCommit.getCommitTime()) lastCommit = commit; } else { lastCommit = commit; } } } } catch (IOException e) { throw new RuntimeException(e); } lastCommitHolder = Optional.fromNullable(lastCommit); } return lastCommitHolder.orNull(); }
Example #5
Source File: Branch.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@PropertyDescription(name = GitConstants.KEY_REMOTE) private JSONArray getRemotes() throws URISyntaxException, JSONException, IOException, CoreException { String branchName = Repository.shortenRefName(ref.getName()); String remoteName = getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig()); ArrayList<JSONObject> remotes = new ArrayList<JSONObject>(); for (RemoteConfig remoteConfig : remoteConfigs) { if (!remoteConfig.getFetchRefSpecs().isEmpty()) { Remote r = new Remote(cloneLocation, db, remoteConfig.getName()); r.setNewBranch(branchName); // Ensure that the remote tracking branch is the first in the list. // Insert at the beginning of the list as well when the remote tracking branch is not set but the branch has been pushed to the remote if (remoteConfig.getName().equals(remoteName) || (remoteName == null && db.resolve(Constants.R_REMOTES + remoteConfig.getName() + "/" + branchName) != null)) { remotes.add(0, r.toJSON()); } else { remotes.add(r.toJSON()); } } } JSONArray result = new JSONArray(); for (JSONObject remote : remotes) { result.put(remote); } return result; }
Example #6
Source File: UIGit.java From hop with Apache License 2.0 | 6 votes |
@Override public void revertPath( String path ) { try { // Delete added files Status status = git.status().addPath( path ).call(); if ( status.getUntracked().size() != 0 || status.getAdded().size() != 0 ) { resetPath( path ); org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, path ) ); } /* * This is a work-around to discard changes of conflicting files * Git CLI `git checkout -- conflicted.txt` discards the changes, but jgit does not */ git.add().addFilepattern( path ).call(); git.checkout().setStartPoint( Constants.HEAD ).addPath( path ).call(); org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, path + ".ours" ) ); org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, path + ".theirs" ) ); } catch ( Exception e ) { showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() ); } }
Example #7
Source File: PullTest.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void setUp() throws Exception { super.setUp(); workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); otherWT = new File(workDir.getParentFile(), "repo2"); GitClient client = getClient(otherWT); client.init(NULL_PROGRESS_MONITOR); f = new File(otherWT, "f"); write(f, "init"); f2 = new File(otherWT, "f2"); write(f2, "init"); client.add(new File[] { f, f2 }, NULL_PROGRESS_MONITOR); masterInfo = client.commit(new File[] { f, f2 }, "init commit", null, null, NULL_PROGRESS_MONITOR); branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR); RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin"); cfg.addURI(new URIish(otherWT.toURI().toURL().toString())); cfg.update(repository.getConfig()); repository.getConfig().save(); }
Example #8
Source File: GitDeltaConsumer.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
boolean migrateFilter(@NotNull GitFilter filter) throws IOException { if (newFilter == null || objectId == null) { throw new IllegalStateException("Original object ID defined, but original Filter is not defined"); } final GitObject<ObjectId> beforeId = objectId; if (!newFilter.equals(filter)) { final Repository repo = writer.getBranch().getRepository().getGit(); try (TemporaryOutputStream content = new TemporaryOutputStream()) { try (InputStream inputStream = newFilter.inputStream(objectId); OutputStream outputStream = filter.outputStream(new UncloseableOutputStream(content), user)) { IOUtils.copy(inputStream, outputStream); } try (InputStream inputStream = content.toInputStream()) { objectId = new GitObject<>(repo, writer.getInserter().insert(Constants.OBJ_BLOB, content.size(), inputStream)); newFilter = filter; } } } return !beforeId.equals(objectId); }
Example #9
Source File: CheckoutTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testCheckoutRevisionAddRemoveFile () throws Exception { File file = new File(workDir, "file"); write(file, "initial"); File[] files = new File[] { file }; add(files); GitClient client = getClient(workDir); GitRevisionInfo info = client.commit(files, "initial", null, null, NULL_PROGRESS_MONITOR); client.createBranch(BRANCH, info.getRevision(), NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); remove(false, file); commit(files); // test checkout // the file is added to WT client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); assertTrue(file.exists()); Map<File, GitStatus> statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); // the file is removed from WT client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); assertFalse(file.exists()); statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); assertNull(statuses.get(file)); }
Example #10
Source File: Utils.java From netbeans with Apache License 2.0 | 6 votes |
public static GitBranch getTrackedBranch (Config config, String branchName, Map<String, GitBranch> allBranches) { String remoteName = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); String trackedBranchName = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); if (trackedBranchName != null) { if (trackedBranchName.startsWith(Constants.R_HEADS)) { trackedBranchName = trackedBranchName.substring(Constants.R_HEADS.length()); } else if (trackedBranchName.startsWith(Constants.R_REMOTES)) { trackedBranchName = trackedBranchName.substring(Constants.R_REMOTES.length()); } } if (trackedBranchName == null) { return null; } else { if (remoteName != null && ".".equals(remoteName)) { //NOI18N remoteName = ""; //NOI18N } else { remoteName = remoteName + "/"; //NOI18N } return allBranches.get(remoteName + trackedBranchName); } }
Example #11
Source File: Change.java From rewrite with Apache License 2.0 | 6 votes |
InMemoryDiffEntry(Path filePath, @Nullable Path relativeTo, String oldSource, String newSource) { this.changeType = ChangeType.MODIFY; var relativePath = relativeTo == null ? filePath : relativeTo.relativize(filePath); this.oldPath = relativePath.toString(); this.newPath = relativePath.toString(); try { this.repo = new InMemoryRepository.Builder().build(); var inserter = repo.getObjectDatabase().newInserter(); oldId = inserter.insert(Constants.OBJ_BLOB, oldSource.getBytes()).abbreviate(40); newId = inserter.insert(Constants.OBJ_BLOB, newSource.getBytes()).abbreviate(40); inserter.flush(); oldMode = FileMode.REGULAR_FILE; newMode = FileMode.REGULAR_FILE; repo.close(); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #12
Source File: Scenarios.java From jgitver with Apache License 2.0 | 6 votes |
/** * Merges commit with id given as parameter with current branch using given FastForwardMode. * @param sourceId the application identifier to use as merge source * @param id the application identifier to use to store the git commitID of merge commit * @param mode the non null fast forward strategy to use for the merge * @return the builder itself to continue building the scenario */ public ScenarioBuilder merge(String sourceId, String id, MergeCommand.FastForwardMode mode) { try { ObjectId other = scenario.getCommits().get(sourceId); ObjectId head = repository.resolve(Constants.HEAD); String nameOfHead = scenario.nameOf(head); MergeResult rc = git.merge() .setFastForward(mode) .setMessage(String.format("%s :: merge %s into %s", id, sourceId, nameOfHead)) .include(other) .call(); scenario.getCommits().put(id, rc.getNewHead()); } catch (Exception ex) { throw new IllegalStateException(String.format("error merging %s", id), ex); } return this; }
Example #13
Source File: CatTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testCatRemoved () throws Exception { File f = new File(workDir, "removed"); copyFile(getGoldenFile(), f); assertFile(getGoldenFile(), f); add(f); commit(f); GitClient client = getClient(workDir); String revision = new Git(repository).log().call().iterator().next().getId().getName(); // remove and commit client.remove(new File[] { f }, false, NULL_PROGRESS_MONITOR); commit(f); assertTrue(client.catFile(f, revision, new FileOutputStream(f), NULL_PROGRESS_MONITOR)); assertFile(f, getGoldenFile()); assertFalse(client.catFile(f, Constants.HEAD, new FileOutputStream(f), NULL_PROGRESS_MONITOR)); }
Example #14
Source File: GiteaPushSCMEvent.java From gitea-plugin with MIT License | 5 votes |
/** * {@inheritDoc} */ @NonNull @Override public Map<SCMHead, SCMRevision> headsFor(GiteaSCMSource source) { String ref = getPayload().getRef(); ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref; BranchSCMHead h = new BranchSCMHead(ref); return Collections.<SCMHead, SCMRevision>singletonMap(h, StringUtils.isNotBlank(getPayload().getAfter()) ? new BranchSCMRevision(h, getPayload().getAfter()) : null); }
Example #15
Source File: IgnoreTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testIgnoreFileWithStarChar () throws Exception { if (isWindows()) { // win do not allow '*' in filename return; } File f = new File(workDir, "fi*le"); f.createNewFile(); File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE); File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR); assertEquals("/fi[*]le", read(gitIgnore)); assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores)); write(gitIgnore, "/fi[*]le"); GitStatus st = getClient(workDir).getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f); assertEquals(Status.STATUS_IGNORED, st.getStatusIndexWC()); ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR); assertEquals("/fi[*]le", read(gitIgnore)); assertEquals(0, ignores.length); write(gitIgnore, "/fi\\*le"); // jgit seems to incorrectly handle escaped wildcards st = getClient(workDir).getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f); assertEquals(Status.STATUS_IGNORED, st.getStatusIndexWC()); ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR); assertEquals("/fi\\*le", read(gitIgnore)); assertEquals(0, ignores.length); }
Example #16
Source File: IgnoreTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testIgnoreIgnoredEqualPath_NestedIgnoreFile () throws Exception { File f = new File(new File(new File(workDir, "sf1"), "sf2"), "file"); f.getParentFile().mkdirs(); f.createNewFile(); File gitIgnore = new File(f.getParentFile(), Constants.DOT_GIT_IGNORE); write(gitIgnore, "/file"); File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR); assertTrue(gitIgnore.exists()); assertEquals("/file", read(gitIgnore)); assertFalse(new File(workDir, Constants.DOT_GIT_IGNORE).exists()); assertEquals(0, ignores.length); }
Example #17
Source File: GiteaCreateSCMEvent.java From gitea-plugin with MIT License | 5 votes |
/** * {@inheritDoc} */ @NonNull @Override public Map<SCMHead, SCMRevision> headsFor(GiteaSCMSource source) { String ref = getPayload().getRef(); ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref; BranchSCMHead h = new BranchSCMHead(ref); return Collections.<SCMHead, SCMRevision>singletonMap(h, new BranchSCMRevision(h, getPayload().getSha())); }
Example #18
Source File: ReleasePlugin.java From curiostack with MIT License | 5 votes |
private static String determineVersion(Project project) { String revisionId; if (project.hasProperty("curiostack.revisionId")) { revisionId = (String) project.property("curiostack.revisionId"); } else if (System.getenv().containsKey("REVISION_ID")) { revisionId = System.getenv("REVISION_ID"); } else if (!Strings.isNullOrEmpty(System.getenv().get("TAG_NAME"))) { revisionId = System.getenv("TAG_NAME"); } else if (!Strings.isNullOrEmpty(System.getenv().get("BRANCH_NAME"))) { revisionId = System.getenv("BRANCH_NAME"); } else { try (Git git = Git.open(project.getRootDir())) { revisionId = git.getRepository().resolve(Constants.HEAD).getName().substring(0, 12); } catch (IOException e) { revisionId = "unknown"; } } checkNotNull(revisionId); boolean isRelease = "true".equals(project.findProperty("curiostack.release")); if (isRelease) { return revisionId; } else { return "0.0.0-" + TIMESTAMP_FORMATTER.format(LocalDateTime.now(ZoneOffset.UTC)) + "-" + revisionId; } }
Example #19
Source File: Project.java From onedev with MIT License | 5 votes |
public List<RefInfo> getBranchRefInfos() { List<RefInfo> refInfos = getRefInfos(Constants.R_HEADS); for (Iterator<RefInfo> it = refInfos.iterator(); it.hasNext();) { RefInfo refInfo = it.next(); if (refInfo.getRef().getName().equals(GitUtils.branch2ref(getDefaultBranch()))) { it.remove(); refInfos.add(0, refInfo); break; } } return refInfos; }
Example #20
Source File: GitHubSCMFile.java From github-branch-source-plugin with MIT License | 5 votes |
@NonNull @Override public Iterable<SCMFile> children() throws IOException { checkOpen(); List<GHContent> content = repo.getDirectoryContent(getPath(), ref.indexOf('/') == -1 ? ref : Constants.R_REFS + ref); List<SCMFile> result = new ArrayList<>(content.size()); for (GHContent c : content) { result.add(new GitHubSCMFile(this, c.getName(), c)); } return result; }
Example #21
Source File: DefaultIndexManager.java From onedev with MIT License | 5 votes |
@Sessional @Listen public void on(RefUpdated event) { // only index branches at back end, tags will be indexed on demand from GUI // as many tags might be pushed all at once when the repository is imported if (event.getRefName().startsWith(Constants.R_HEADS) && !event.getNewCommitId().equals(ObjectId.zeroId())) { IndexWork work = new IndexWork(BACKEND_INDEXING_PRIORITY, event.getNewCommitId()); batchWorkManager.submit(getBatchWorker(event.getProject().getId()), work); } }
Example #22
Source File: SetUpstreamBranchTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testLocalTracking () throws GitException { GitClient client = getClient(workDir); File f = new File(workDir, "f"); add(f); client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); // prepare twp branches GitBranch b = client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); assertNull(b.getTrackedBranch()); // set tracking b = client.setUpstreamBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); assertEquals(Constants.MASTER, b.getTrackedBranch().getName()); }
Example #23
Source File: StatusCommand.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected String getCommandDescription () { StringBuilder sb = new StringBuilder("git "); //NOI18N if (Constants.HEAD.equals(revision)) { sb.append("status"); //NOI18N } else { sb.append("diff --raw"); //NOI18N } for (File root : roots) { sb.append(" ").append(root.getAbsolutePath()); } return sb.toString(); }
Example #24
Source File: GitCloneTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testCloneAndLink() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String workspaceId = workspaceIdFromLocation(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null); String contentLocation = clone(workspaceId, project).getString(ProtocolConstants.KEY_CONTENT_LOCATION); File contentFile = getRepositoryForContentLocation(contentLocation).getDirectory().getParentFile(); JSONObject newProject = createProjectOrLink(workspaceLocation, getMethodName().concat("-link"), contentFile.toString()); String projectContentLocation = newProject.getString(ProtocolConstants.KEY_CONTENT_LOCATION); // http://<host>/file/<projectId>/ WebRequest request = getGetRequest(projectContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject link = new JSONObject(response.getText()); String childrenLocation = link.getString(ProtocolConstants.KEY_CHILDREN_LOCATION); assertNotNull(childrenLocation); // http://<host>/file/<projectId>/?depth=1 request = getGetRequest(childrenLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); List<JSONObject> children = getDirectoryChildren(new JSONObject(response.getText())); String[] expectedChildren = new String[] {Constants.DOT_GIT, "folder", "test.txt"}; assertEquals("Wrong number of directory children", expectedChildren.length, children.size()); assertNotNull(getChildByName(children, expectedChildren[0])); assertNotNull(getChildByName(children, expectedChildren[1])); assertNotNull(getChildByName(children, expectedChildren[2])); }
Example #25
Source File: CherryPickTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testCherryPickCommitsConflictAbort () throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); File[] roots = new File[] { f }; GitClient client = getClient(workDir); client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); write(f, "change 1 on branch"); add(f); GitRevisionInfo c1 = client.commit(roots, "on branch 1", null, null, NULL_PROGRESS_MONITOR); write(f, "change 2 on branch"); add(f); GitRevisionInfo c2 = client.commit(roots, "on branch 2", null, null, NULL_PROGRESS_MONITOR); write(f, "change 3 on branch"); add(f); GitRevisionInfo c3 = client.commit(roots, "on branch 3", null, null, NULL_PROGRESS_MONITOR); client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); GitRevisionInfo initCommit = client.log("HEAD", NULL_PROGRESS_MONITOR); GitCherryPickResult res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, new String[] { c1.getRevision(), c3.getRevision() }, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.CONFLICTING, res.getCherryPickStatus()); assertEquals(1, res.getConflicts().size()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getParents()[0]); res = client.cherryPick(GitClient.CherryPickOperation.ABORT, null, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.ABORTED, res.getCherryPickStatus()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getRevision()); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); }
Example #26
Source File: GitConnector.java From compiler with Apache License 2.0 | 5 votes |
@Override public List<ChangedFile> buildHeadSnapshot() { final List<ChangedFile> snapshot = new ArrayList<ChangedFile>(); TreeWalk tw = new TreeWalk(repository); tw.reset(); try { RevCommit rc = revwalk.parseCommit(repository.resolve(Constants.HEAD)); tw.addTree(rc.getTree()); tw.setRecursive(true); while (tw.next()) { if (!tw.isSubtree()) { String path = tw.getPathString(); ChangedFile.Builder cfb = ChangedFile.newBuilder(); cfb.setChange(ChangeKind.UNKNOWN); cfb.setName(path); cfb.setKind(FileKind.OTHER); cfb.setKey(0); cfb.setAst(false); GitCommit gc = new GitCommit(this, repository, revwalk, projectName); gc.filePathGitObjectIds.put(path, tw.getObjectId(0)); gc.processChangeFile(cfb); snapshot.add(cfb.build()); } } } catch (Exception e) { System.err.println(e.getMessage()); } tw.close(); return snapshot; }
Example #27
Source File: LocalFacadeTest.java From sputnik with Apache License 2.0 | 5 votes |
private void setUpDiff() throws IOException { when(modifiedFile.getNewPath()).thenReturn("/path/to/modifiedFile"); when(modifiedFile.getChangeType()).thenReturn(ChangeType.MODIFY); when(newFile.getNewPath()).thenReturn("/path/to/newFile"); when(newFile.getChangeType()).thenReturn(ChangeType.ADD); when(deletedFile.getChangeType()).thenReturn(ChangeType.DELETE); ObjectId head = mock(ObjectId.class); ObjectId headParent = mock(ObjectId.class); when(repo.resolve(Constants.HEAD)).thenReturn(head); when(repo.resolve(Constants.HEAD + "^")).thenReturn(headParent); when(diffFormatter.scan(headParent, head)).thenReturn(ImmutableList.of(modifiedFile, deletedFile, newFile)); }
Example #28
Source File: BranchUtilsTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void getBranchHeadCommitTest() throws IOException { AnyObjectId firstCommit = initRepository(); assertEquals(firstCommit, BranchUtils.getHeadCommit(Constants.MASTER, repo)); writeToCache("a.txt"); String branchName = "second"; AnyObjectId branchCommit = commitToBranch(branchName, firstCommit); assertEquals(branchCommit, BranchUtils.getHeadCommit(branchName, repo)); }
Example #29
Source File: RevCommit.java From onedev with MIT License | 5 votes |
/** {@inheritDoc} */ @Override public String toString() { final StringBuilder s = new StringBuilder(); s.append(Constants.typeString(getType())); s.append(' '); s.append(name()); s.append(' '); s.append(commitTime); s.append(' '); appendCoreFlags(s); return s.toString(); }
Example #30
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")); } }