Example usage for org.eclipse.jgit.lib Constants R_HEADS

List of usage examples for org.eclipse.jgit.lib Constants R_HEADS

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants R_HEADS.

Prototype

String R_HEADS

To view the source code for org.eclipse.jgit.lib Constants R_HEADS.

Click Source Link

Document

Prefix for branch refs

Usage

From source file:org.uberfire.java.nio.fs.jgit.util.commands.SimpleRefUpdateCommand.java

License:Apache License

public void execute() throws IOException, ConcurrentRefUpdateException {
    final ObjectId headId = git.getLastCommit(Constants.R_HEADS + name);
    final RefUpdate ru = git.getRepository().updateRef(Constants.R_HEADS + name);
    if (headId == null) {
        ru.setExpectedOldObjectId(ObjectId.zeroId());
    } else {/*from ww  w . ja  v  a2s .co m*/
        ru.setExpectedOldObjectId(headId);
    }
    ru.setNewObjectId(commit.getId());
    ru.setRefLogMessage(commit.getShortMessage(), false);
    forceUpdate(ru, commit.getId());
}

From source file:org.webcat.core.FilePickerDialog.java

License:Open Source License

private GitRef refForModelObject(Object object) {
    GitRef ref;// ww w  .  j  a va2 s  . c om

    if (object instanceof EOBase) {
        GitRepository repo = GitRepository.repositoryForObject((EOBase) object);
        ref = repo.refWithName(Constants.R_HEADS + Constants.MASTER);
    } else {
        ref = (GitRef) object;
    }

    return ref;
}

From source file:org.webcat.core.git.GitCloner.java

License:Open Source License

private Repository createWorkingCopyRepositoryIfNecessary(File location, File remoteDir) throws IOException {
    Repository wcRepository;/*from   ww w.j a  va2  s. co  m*/

    try {
        wcRepository = RepositoryCache.open(FileKey.lenient(location, FS.DETECTED));
    } catch (RepositoryNotFoundException e) {
        // Create the repository from scratch.

        if (!location.exists()) {
            location.mkdirs();
        }

        InitCommand init = Git.init();
        init.setDirectory(location);
        init.setBare(false);
        wcRepository = init.call().getRepository();

        StoredConfig config = wcRepository.getConfig();
        config.setBoolean("core", null, "bare", false);

        try {
            RefSpec refSpec = new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*",
                    Constants.R_REMOTES + "origin" + "/*");

            RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
            remoteConfig.addURI(new URIish(remoteDir.toString()));
            remoteConfig.addFetchRefSpec(refSpec);
            remoteConfig.update(config);
        } catch (URISyntaxException e2) {
            // Do nothing.
        }

        config.save();
    }

    return wcRepository;
}

From source file:org.webcat.core.git.GitCloner.java

License:Open Source License

private Ref guessHead(FetchResult result) {
    Ref idHEAD = result.getAdvertisedRef(Constants.HEAD);
    List<Ref> availableRefs = new ArrayList<Ref>();
    Ref head = null;/* w  ww  . j  a  v  a 2  s  .  com*/

    for (Ref ref : result.getAdvertisedRefs()) {
        String name = ref.getName();

        if (!name.startsWith(Constants.R_HEADS)) {
            continue;
        }

        availableRefs.add(ref);

        if (idHEAD == null || head != null) {
            continue;
        }

        if (ref.getObjectId().equals(idHEAD.getObjectId())) {
            head = ref;
        }
    }

    Collections.sort(availableRefs, RefComparator.INSTANCE);

    if (idHEAD != null && head == null) {
        head = idHEAD;
    }

    return head;
}

From source file:org.webcat.core.git.GitRef.java

License:Open Source License

public boolean isHead() {
    return name().startsWith(Constants.R_HEADS);
}

From source file:org.webcat.core.git.GitRef.java

License:Open Source License

public boolean isMaster() {
    return name().equals(Constants.R_HEADS + Constants.MASTER);
}

From source file:org.webcat.core.git.GitRef.java

License:Open Source License

public String shortName() {
    if (isHead()) {
        return name().substring(Constants.R_HEADS.length());
    } else if (isTag()) {
        return name().substring(Constants.R_TAGS.length());
    } else {//www . j  a  va2  s  . co  m
        return name();
    }
}

From source file:org.webcat.core.git.GitRepository.java

License:Open Source License

public NSArray<GitRef> headRefs() {
    return filteredRefs(new RefFilter() {
        public boolean accepts(Ref ref) {
            return ref.getName().startsWith(Constants.R_HEADS);
        }/*ww w .  ja va  2 s.  c o m*/
    });
}

From source file:org.webcat.core.git.GitUtilities.java

License:Open Source License

@SuppressWarnings("deprecation")
public static RevCommit pushWorkingCopyImmediately(Repository workingCopy, String authorName,
        String emailAddress, String commitMessage) {
    try {/*from   w  w w .jav  a  2 s  . c om*/
        boolean amend = false;

        GitRepository gitRepo = new GitRepository(workingCopy);
        GitRef ref = gitRepo.refWithName(Constants.R_HEADS + Constants.MASTER);
        NSArray<GitCommit> commits = ref.commits();

        if (commits != null && !commits.isEmpty()) {
            GitCommit commit = commits.objectAtIndex(0);
            if (commitMessage.equals(commit.shortMessage())
                    && commit.commitTime().timeIntervalSinceNow() > -3 * 60 * 60) {
                amend = true;
            }
        }

        Git git = new Git(workingCopy);

        git.add().addFilepattern(".").setUpdate(false).call();

        RevCommit commit = git.commit().setAuthor(authorName, emailAddress)
                .setCommitter(authorName, emailAddress).setMessage(commitMessage).setAmend(amend).call();

        RefSpec allHeadsSpec = new RefSpec().setForceUpdate(true).setSourceDestination(
                Constants.R_HEADS + Constants.MASTER, Constants.R_HEADS + Constants.MASTER);

        git.push().setRefSpecs(allHeadsSpec).call();

        return commit;
    } catch (Exception e) {
        log.error("Error updating repository: ", e);
    }

    return null;
}

From source file:org.webcat.core.RepositoryEntryRef.java

License:Open Source License

public static RepositoryEntryRef fromOldStylePath(String path) {
    Pattern pattern = Pattern.compile("^([^/]+)/([^/]+)(?:/(.*))?$");
    Matcher matcher = pattern.matcher(path);

    if (matcher.matches()) {
        String authDomain = matcher.group(1);
        String username = matcher.group(2);
        String repoPath = matcher.group(3);

        // Make sure a slash is added to the end of old-style paths that
        // point to directories.
        File oldPath = new File(User.userDataRoot(), path);
        if (oldPath.isDirectory()) {
            repoPath += "/";
        }// w  w  w  .  j  av a  2 s  .c  o m

        return new RepositoryEntryRef("User/" + authDomain + "." + username, repoPath,
                Constants.R_HEADS + Constants.MASTER);
    } else {
        return null;
    }
}