Java 类org.eclipse.jgit.lib.Constants 实例源码

项目:incubator-netbeans    文件:PullCommand.java   
private String findRemoteBranchName () throws GitException {
    Ref ref = null;
    try {
        ref = getRepository().getRef(branchToMerge);
    } catch (IOException ex) {
        throw new GitException(ex);
    }
    if (ref != null) {
        for (String s : refSpecs) {
            RefSpec spec = new RefSpec(s);
            if (spec.matchDestination(ref)) {
                spec = spec.expandFromDestination(ref);
                String refName = spec.getSource();
                if (refName.startsWith(Constants.R_HEADS)) {
                    return refName.substring(Constants.R_HEADS.length());
                }
            }
        }
    }
    return branchToMerge;
}
项目:pdi-git-plugin    文件:UIGit.java   
@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() );
  }
}
项目:incubator-netbeans    文件:RebaseCommand.java   
private GitRebaseResult createResult (RebaseResult res) {
    String currHead;
    Repository repository = getRepository();
    File workTree = repository.getWorkTree();
    try {
        currHead = repository.resolve(Constants.HEAD).name();
    } catch (IOException ex) {
        currHead = Constants.HEAD;
    }
    List<File> conflicts;
    if (res.getStatus() == RebaseResult.Status.STOPPED) {
        conflicts = getConflicts(res.getCurrentCommit());
    } else {
        conflicts = Collections.<File>emptyList();
    }
    return getClassFactory().createRebaseResult(res, conflicts, getFailures(res), currHead);
}
项目:incubator-netbeans    文件:GitTransportUpdate.java   
private static String stripRefs (String refName) {
    if (refName == null) {

    } else if (refName.startsWith(Constants.R_HEADS)) {
        refName = refName.substring(Constants.R_HEADS.length());
    } else if (refName.startsWith(Constants.R_TAGS)) {
        refName = refName.substring(Constants.R_TAGS.length());
    } else if (refName.startsWith(Constants.R_REMOTES)) {
        refName = refName.substring(Constants.R_REMOTES.length());
    } else if (refName.startsWith(Constants.R_REFS)) {
        refName = refName.substring(Constants.R_REFS.length());
    } else {
        throw new IllegalArgumentException("Unknown refName: " + refName);
    }
    return refName;
}
项目:incubator-netbeans    文件:GitTag.java   
private GitObjectType getType (RevObject object) {
    GitObjectType objType = GitObjectType.UNKNOWN;
    if (object != null) {
        switch (object.getType()) {
            case Constants.OBJ_COMMIT:
                objType = GitObjectType.COMMIT;
                break;
            case Constants.OBJ_BLOB:
                objType = GitObjectType.BLOB;
                break;
            case Constants.OBJ_TAG:
                objType = GitObjectType.TAG;
                break;
            case Constants.OBJ_TREE:
                objType = GitObjectType.TREE;
                break;
        }
    }
    return objType;
}
项目:incubator-netbeans    文件:GitClient.java   
/**
 * Exports uncommitted changes in files under given roots to the given output stream
 * @param roots the diff will be exported only for modified files under these roots, can be empty to export all modifications in the whole working tree
 * @param mode defines the compared trees 
 * @param out output stream the diff will be printed to
 * @param monitor progress monitor
 * @throws GitException an unexpected error occurs
 */
public void exportDiff (File[] roots, DiffMode mode, OutputStream out, ProgressMonitor monitor) throws GitException {
    switch (mode) {
        case HEAD_VS_INDEX:
            exportDiff(roots, Constants.HEAD, INDEX, out, monitor);
            break;
        case HEAD_VS_WORKINGTREE:
            exportDiff(roots, Constants.HEAD, WORKING_TREE, out, monitor);
            break;
        case INDEX_VS_WORKINGTREE:
            exportDiff(roots, INDEX, WORKING_TREE, out, monitor);
            break;
        default:
            throw new IllegalArgumentException("Unknown diff mode: " + mode);
    }
}
项目:incubator-netbeans    文件:IgnoreTest.java   
public void testIgnoreFolderIgnoredEqualPath () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\n/sf1/sf2/folder/");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(0, ignores.length);

    write(gitIgnore, "#ignoreFile\n/sf1/sf2/folder");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf1/sf2/folder", read(gitIgnore));
    assertEquals(0, ignores.length);
}
项目:incubator-netbeans    文件:IgnoreTest.java   
public void testIgnoreFolderIgnoredPartialEqualPath () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    new File(f, "file").createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\nfolder");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\nfolder", read(gitIgnore));
    assertEquals(0, ignores.length);

    write(gitIgnore, "#ignoreFile\nfolder/");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\nfolder/", read(gitIgnore));
    assertEquals(0, ignores.length);
}
项目:incubator-netbeans    文件:IgnoreTest.java   
public void testIgnoreRemoveNegation () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "file");
    f.getParentFile().mkdirs();
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\n/sf1/sf2/file\n!/sf1/sf2/file");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf1/sf2/file", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "");
    File ignore2 = new File(f.getParentFile().getParentFile(), Constants.DOT_GIT_IGNORE);
    write(ignore2, "!sf2/file");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("/sf1/sf2/file", read(gitIgnore));
    assertEquals("", read(ignore2));
    assertEquals(Arrays.asList(ignore2, gitIgnore), Arrays.asList(ignores));
}
项目:incubator-netbeans    文件:IgnoreTest.java   
public void testIgnoreFolderNoNegationRemoval () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\n/sf1/sf2/folder\n!folder");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf1/sf2/folder\n!folder\n/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "#ignoreFile\n/sf1/sf2/folder\n!/sf1/sf2/folder");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf1/sf2/folder\n!/sf1/sf2/folder\n/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
项目:incubator-netbeans    文件:CatTest.java   
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));
}
项目:incubator-netbeans    文件:IgnoreTest.java   
public void testIgnoreRemoveNegation_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().getParentFile(), Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\n/sf2/file\n!/sf2/file");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf2/file", read(gitIgnore));
    assertFalse(new File(workDir, Constants.DOT_GIT_IGNORE).exists());
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "sf2/file\n!sf2/file");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("sf2/file", read(gitIgnore));
    assertFalse(new File(workDir, Constants.DOT_GIT_IGNORE).exists());
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "#ignoreFile\nsf2/f*\n!/sf2/file");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\nsf2/f*", read(gitIgnore));
    assertFalse(new File(workDir, Constants.DOT_GIT_IGNORE).exists());
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
项目:incubator-netbeans    文件:IgnoreTest.java   
public void testIgnoreFolderRemoveNegation_NestedIgnoreFile () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(f.getParentFile().getParentFile(), Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "#ignoreFile\n/sf2/folder/\n!/sf2/folder/");
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\n/sf2/folder/", read(gitIgnore));
    assertFalse(new File(workDir, Constants.DOT_GIT_IGNORE).exists());
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "#ignoreFile\nsf2/f*\n!/sf2/folder/");
    ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("#ignoreFile\nsf2/f*", read(gitIgnore));
    assertFalse(new File(workDir, Constants.DOT_GIT_IGNORE).exists());
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
项目:incubator-netbeans    文件:IgnoreTest.java   
public void testIgnoreFileWithBracket () throws Exception {
    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);
}
项目:incubator-netbeans    文件:UnignoreTest.java   
public void testUnignoreFolderWithNegation () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    write(gitIgnore, "/sf1/sf2/folder/\n!/sf1/sf2/folder/");
    File[] ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("!/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "/sf1/sf2/folder\n!/sf1/sf2/folder/");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("/sf1/sf2/folder\n!/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(0, ignores.length);

    write(gitIgnore, "!/sf1/sf2/folder/\n/sf1/sf2/folder/");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("!/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
项目:incubator-netbeans    文件:BranchTest.java   
public void testListBranches_Issue213538 () throws Exception {
    GitClient client = getClient(workDir);
    File f = new File(workDir, "f");
    write(f, "init");
    client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
    client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);

    // cannot end with a RuntimeException
    File configFile = new File(Utils.getMetadataFolder(workDir), Constants.CONFIG);
    String config = read(configFile);
    config += "\n\tbla:\n";
    write(configFile, config);
    Thread.sleep(1100);
    try {
        client.getBranches(false, NULL_PROGRESS_MONITOR);
    } catch (GitException ex) {
        assertEquals("It seems the config file for repository at [" + workDir + "] is corrupted.\nEnsure it's valid.", ex.getMessage());
    }
}
项目:pdi-git-plugin    文件:UIGit.java   
private boolean mergeBranch( String value, String mergeStrategy ) {
  try {
    ObjectId obj = git.getRepository().resolve( value );
    MergeResult result = git.merge()
      .include( obj )
      .setStrategy( MergeStrategy.get( mergeStrategy ) )
      .call();
    if ( result.getMergeStatus().isSuccessful() ) {
      showMessageBox( BaseMessages.getString( PKG, "Dialog.Success" ), BaseMessages.getString( PKG, "Dialog.Success" ) );
      return true;
    } else {
      showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), result.getMergeStatus().toString() );
      if ( result.getMergeStatus() == MergeStatus.CONFLICTING ) {
        result.getConflicts().keySet().forEach( path -> {
          checkout( path, Constants.HEAD, ".ours" );
          checkout( path, getExpandedName( value, IVCS.TYPE_BRANCH ), ".theirs" );
        } );
        return true;
      }
    }
  } catch ( Exception e ) {
    showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() );
  }
  return false;
}
项目:incubator-netbeans    文件:CheckoutTest.java   
private void checkJGitFix (String branch, File file) throws Exception {
    ObjectId headTree = null;
    try {
        headTree = Utils.findCommit(repository, Constants.HEAD).getTree();
    } catch (GitException.MissingObjectException ex) { }

    DirCache cache = repository.lockDirCache();
    RevCommit commit;
    commit = Utils.findCommit(repository, branch);
    DirCacheCheckout dco = new DirCacheCheckout(repository, headTree, cache, commit.getTree());
    dco.setFailOnConflict(false);
    dco.checkout();
    if (file.exists()) {
        // and do not forget to remove WA in checkout command when JGit is fixed.
        fail("Hey, JGit is fixed, why don't you fix me as well?");
    }
    cache.unlock();
}
项目:incubator-netbeans    文件:CompareCommitTest.java   
public void testCompareRevertModification () throws Exception {
    File file = new File(workDir, "file");
    File[] files = new File[] { file };
    write(file, "init\n");
    add(files);
    commit(files);

    GitClient client = getClient(workDir);
    String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId();
    write(file, "modification\n");
    add(files);
    GitRevisionInfo revision2 = client.commit(files, "my commit message", null, null, NULL_PROGRESS_MONITOR);

    write(file, "init\n");
    add(files);
    GitRevisionInfo revision3 = client.commit(files, "my commit 3 message", null, null, NULL_PROGRESS_MONITOR);
    Map<File, GitRevisionInfo.GitFileInfo> statuses = client.getStatus(files, revision1, Constants.HEAD, NULL_PROGRESS_MONITOR);
    assertTrue(statuses.isEmpty());
}
项目:gitplex-mit    文件:Project.java   
@Nullable
public String getDefaultBranch() {
    if (defaultBranchOptional == null) {
        try {
            Ref headRef = getRepository().findRef("HEAD");
            if (headRef != null 
                    && headRef.isSymbolic() 
                    && headRef.getTarget().getName().startsWith(Constants.R_HEADS) 
                    && headRef.getObjectId() != null) {
                defaultBranchOptional = Optional.of(Repository.shortenRefName(headRef.getTarget().getName()));
            } else {
                defaultBranchOptional = Optional.absent();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return defaultBranchOptional.orNull();
}
项目:incubator-netbeans    文件:FetchTest.java   
@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");
    client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
    masterInfo = client.commit(new File[] { f }, "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();
}
项目:incubator-netbeans    文件:AddTest.java   
private void assertDirCacheEntryModified (Collection<File> files) throws IOException {
    DirCache cache = repository.lockDirCache();
    for (File f : files) {
        String relativePath = Utils.getRelativePath(workDir, f);
        DirCacheEntry e = cache.getEntry(relativePath);
        assertNotNull(e);
        assertEquals(relativePath, e.getPathString());
        InputStream in = new FileInputStream(f);
        try {
            assertNotSame(e.getObjectId(), repository.newObjectInserter().idFor(Constants.OBJ_BLOB, f.length(), in));
        } finally {
            in.close();
        }
    }
    cache.unlock();
}
项目:incubator-netbeans    文件:UnignoreTest.java   
public void testUnignoreFileInRoot () throws Exception {
    File f = new File(workDir, "file");
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertFalse(gitIgnore.exists());
    assertEquals(0, ignores.length);

    write(gitIgnore, "/file");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "f\nf2\n/file\nf3\nf4");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("f\nf2\nf3\nf4", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
项目:gmds    文件:Utils.java   
/**
     *
     * @param datarepo
     * @param tree
     * @param conn
     * @param clmnTree
     * @return
     * @throws SQLException
     * @throws IOException
     */
    public static ObjectId dataTreeCommit(Repository datarepo, TreeFormatter tree, Connection conn, Boolean clmnTree) throws SQLException, IOException {
        DatabaseMetaData dbmd = conn.getMetaData();
//        ObjectJson dbmdJson = new ObjectJson();
        String mapString = metaDbInfo(dbmd);

        // Build Db_Info object, general info about Database
        ObjectInserter objectInserter = datarepo.newObjectInserter();
        ObjectId blobId = objectInserter.insert(Constants.OBJ_BLOB, mapString.getBytes());
        objectInserter.flush();

        tree.append("DATABASE", FileMode.REGULAR_FILE, blobId);

        // Continue building Database Tree
        Utils.putTableMeta(datarepo, conn, dbmd, objectInserter, tree, clmnTree);

        ObjectId treeId = objectInserter.insert(tree);
        objectInserter.flush();

        System.out.println("Tree ID: " + treeId.getName());

        return treeId;
    }
项目:incubator-netbeans    文件:UnignoreTest.java   
public void testUnignoreFolderInRoot () throws Exception {
    File f = new File(workDir, "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertFalse(gitIgnore.exists());
    assertEquals(0, ignores.length);

    write(gitIgnore, "/folder/");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "/folder");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/folder\n!/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
项目:incubator-netbeans    文件:UnignoreTest.java   
public void testUnignoreFileInSubfolder () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "file");
    f.getParentFile().mkdirs();
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertFalse(gitIgnore.exists());
    assertEquals(0, ignores.length);

    write(gitIgnore, "/sf1/sf2/file");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "/sf1/sf2/file/");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/sf1/sf2/file/", read(gitIgnore));
    assertEquals(0, ignores.length);
}
项目:incubator-netbeans    文件:UnignoreTest.java   
public void testUnignoreFolderInSubfolder () throws Exception {
    File f = new File(new File(new File(workDir, "sf1"), "sf2"), "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertFalse(gitIgnore.exists());
    assertEquals(0, ignores.length);

    write(gitIgnore, "sf1/sf2/folder/");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));

    write(gitIgnore, "/sf1/sf2/folder");
    ignores = getClient(workDir).unignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertEquals("/sf1/sf2/folder\n!/sf1/sf2/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
项目:incubator-netbeans    文件:StatusCommand.java   
@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();
}
项目:pdi-git-plugin    文件:GitControllerTest.java   
@Test
public void testVisualDiff() throws Exception {
  XulMessageBox message = spy( new XulMessageBoxMock( XulDialogCallback.Status.ACCEPT ) );
  when( document.createElement( MESSAGEBOX ) ).thenReturn( message );
  UIFile file = new UIFile( "test.txt", ChangeType.MODIFY, true );
  doReturn( Collections.singletonList( file ) ).when( controller ).getSelectedChangedFiles();
  controller.visualdiff();
  verify( message ).setTitle( BaseMessages.getString( PKG, "Dialog.Error" ) );

  // .ktr
  file = new UIFile( "test.ktr", ChangeType.MODIFY, true );
  doReturn( Collections.singletonList( file ) ).when( controller ).getSelectedChangedFiles();
  doReturn( new FileInputStream( new File( "src/test/resources/r1.ktr" ) ) ).when( uiGit ).open( "test.ktr", Constants.HEAD );
  doReturn( new FileInputStream( new File( "src/test/resources/r2.ktr" ) ) ).when( uiGit ).open( "test.ktr", IVCS.WORKINGTREE );
  controller.visualdiff();
  verify( uiGit ).open( "test.ktr", Constants.HEAD );
  verify( uiGit ).open( "test.ktr", IVCS.WORKINGTREE );
  verify( controller ).loadMainPerspective();

  // conflicted ktr
  file = new UIFile( "test.kjb.ours", ChangeType.ADD, false );
  File dir = File.createTempFile( "git_test_", "_controller" );
  dir.delete();
  dir.mkdir();
  File ours = new File( dir.getPath(), "test.kjb.ours" );
  File theirs = new File( dir.getPath(), "test.kjb.theirs" );
  FileUtils.copyFile( new File( "src/test/resources/r1.kjb" ), ours );
  FileUtils.copyFile( new File( "src/test/resources/r2.kjb" ), theirs );
  doReturn( dir.getPath() ).when( uiGit ).getDirectory();
  doReturn( Collections.singletonList( file ) ).when( controller ).getSelectedChangedFiles();
  doReturn( new FileInputStream( ours ) ).when( uiGit ).open( "test.kjb.ours", IVCS.WORKINGTREE );
  doReturn( new FileInputStream( theirs ) ).when( uiGit ).open( "test.kjb.theirs", IVCS.WORKINGTREE );
  controller.visualdiff();
  FileUtils.deleteDirectory( dir );
  verify( uiGit ).open( "test.kjb.ours", IVCS.WORKINGTREE );
  verify( uiGit ).open( "test.kjb.theirs", IVCS.WORKINGTREE );
  verify( controller, times( 2 ) ).loadMainPerspective();
}
项目:incubator-netbeans    文件:CherryPickCommand.java   
private GitRevisionInfo getCurrentHead () {
    GitRevisionInfo currHead;
    Repository repository = getRepository();
    try {
        currHead = getClassFactory().createRevisionInfo(Utils.findCommit(repository, Constants.HEAD), repository);
    } catch (GitException ex) {
        currHead = null;
    }
    return currHead;
}
项目:incubator-netbeans    文件:CheckoutRevisionCommand.java   
private void cacheContents (List<String> conflicts) throws IOException {
    File workTree = getRepository().getWorkTree();
    ObjectInserter inserter = getRepository().newObjectInserter();
    WorkingTreeOptions opt = getRepository().getConfig().get(WorkingTreeOptions.KEY);
    boolean autocrlf = opt.getAutoCRLF() != CoreConfig.AutoCRLF.FALSE;
    try {
        for (String path : conflicts) {
            File f = new File(workTree, path);
            Path p = null;
            try {
                p = f.toPath();
            } catch (InvalidPathException ex) {
                Logger.getLogger(CheckoutRevisionCommand.class.getName()).log(Level.FINE, null, ex);
            }
            if (p != null && Files.isSymbolicLink(p)) {
                Path link = Utils.getLinkPath(p);                                
                cachedContents.put(path, inserter.insert(Constants.OBJ_BLOB, Constants.encode(link.toString())));
            } else if (f.isFile()) {
                long sz = f.length();
                try (FileInputStream in = new FileInputStream(f)) {
                    if (autocrlf) {
                        ByteBuffer buf = IO.readWholeStream(in, (int) sz);
                        cachedContents.put(path, inserter.insert(Constants.OBJ_BLOB, buf.array(), buf.position(), buf.limit() - buf.position()));
                    } else {
                        cachedContents.put(path, inserter.insert(Constants.OBJ_BLOB, sz, in));
                    }
                }
            }
        }
        inserter.flush();
    } finally {
        inserter.release();
    }
}
项目:gerrit-plugin    文件:AbstractGerritSCMSource.java   
/** {@inheritDoc} */
@NonNull
@Override
protected List<Action> retrieveActions(
    @CheckForNull SCMSourceEvent event, @NonNull TaskListener listener)
    throws IOException, InterruptedException {
  return doRetrieve(
      new Retriever<List<Action>>() {
        @Override
        public List<Action> run(
            GitClient client, String remoteName, Changes.QueryRequest queryRequest)
            throws IOException, InterruptedException {
          Map<String, String> symrefs = client.getRemoteSymbolicReferences(getRemote(), null);
          if (symrefs.containsKey(Constants.HEAD)) {
            // Hurrah! The Server is Git 1.8.5 or newer and our client has symref reporting
            String target = symrefs.get(Constants.HEAD);
            if (target.startsWith(Constants.R_HEADS)) {
              // shorten standard names
              target = target.substring(Constants.R_HEADS.length());
            }
            List<Action> result = new ArrayList<>();
            if (StringUtils.isNotBlank(target)) {
              result.add(new GitRemoteHeadRefAction(getRemote(), target));
            }
            result.add(new GerritLogo());
            return result;
          }

          // Give up, there's no way to get the primary branch
          return new ArrayList<>();
        }
      },
      new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits()),
      listener,
      false);
}
项目:gitea-plugin    文件:GiteaPushSCMEvent.java   
/**
 * {@inheritDoc}
 */
@Override
public String description() {
    String ref = getPayload().getRef();
    ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref;
    return "Push event to branch " + ref + " in repository " +
            getPayload().getRepository().getOwner().getUsername() + "/" +
            getPayload().getRepository().getName();
}
项目:incubator-netbeans    文件:Utils.java   
public static Collection<byte[]> getPaths (Collection<PathFilter> pathFilters) {
    Collection<byte[]> paths = new LinkedList<byte[]>();
    for (PathFilter filter : pathFilters) {
        paths.add(Constants.encode(filter.getPath()));
    }
    return paths;
}
项目:incubator-netbeans    文件:Utils.java   
/**
 * Eliminates part of the ref's name that equals knon prefixes such as refs/heads/, refs/remotes/ etc.
 * @param ref
 * @return 
 */
public static String getRefName (Ref ref) {
    String name = ref.getName();
    for (String prefix : Arrays.asList(Constants.R_HEADS, Constants.R_REMOTES, Constants.R_TAGS, Constants.R_REFS)) {
        if (name.startsWith(prefix)) {
            name = name.substring(prefix.length());
        }
    }
    return name;
}
项目:IodineToolkit    文件:PatchService.java   
public RevCommit getSrcCommit() {
    try {
        RevWalk revWalk = new RevWalk(git.getRepository());
        AnyObjectId headId = git.getRepository().resolve(Constants.HEAD);
        RevCommit root = revWalk.parseCommit(headId);
        revWalk.sort(RevSort.REVERSE);
        revWalk.markStart(root);
        return revWalk.next();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:incubator-netbeans    文件:GitTransportUpdate.java   
private Type getType (String refName) {
    Type retval;
    if (refName.startsWith(Constants.R_TAGS)) {
        retval = Type.TAG;
    } else if (refName.startsWith(Constants.R_REMOTES)) {
        retval = Type.BRANCH;
    } else if (refName.startsWith(Constants.R_HEADS)) {
        retval = Type.BRANCH;
    } else if (refName.startsWith(Constants.R_REFS)) {
        retval = Type.REFERENCE;
    } else {
        throw new IllegalArgumentException("Unknown type for: " + refName);
    }
    return retval;
}
项目:centraldogma    文件:GitRepositoryTest.java   
@Test
public void testDoUpdateRefOnExistingTag() throws Exception {
    final ObjectId commitId = mock(ObjectId.class);

    assertThatThrownBy(() -> testDoUpdateRef(Constants.R_TAGS + "01/1.0", commitId, true))
            .isInstanceOf(StorageException.class);
}
项目:incubator-netbeans    文件:IgnoreTest.java   
public void testIgnoreFileInRoot () throws Exception {
    File f = new File(workDir, "file");
    f.createNewFile();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("/file", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}
项目:incubator-netbeans    文件:IgnoreTest.java   
public void testIgnoreFolderInRoot () throws Exception {
    File f = new File(workDir, "folder");
    f.mkdirs();
    File gitIgnore = new File(workDir, Constants.DOT_GIT_IGNORE);
    File[] ignores = getClient(workDir).ignore(new File[] { f }, NULL_PROGRESS_MONITOR);
    assertTrue(gitIgnore.exists());
    assertEquals("/folder/", read(gitIgnore));
    assertEquals(Arrays.asList(gitIgnore), Arrays.asList(ignores));
}