简体   繁体   English

在EGIT储存库中找到“活动”分支

[英]finding “active” branch in EGIT repository

I have to modify a faulty program/feature, which is an extension to org.eclipse.jgit 我必须修改错误的程序/功能,这是org.eclipse.jgit的扩展

the program overrides the close method of the PushResultDialog and passes the Repository to an method. 程序将覆盖PushResultDialog的close方法,并将存储库传递给方法。 Here i want to find the branch which was actually pushed/checked out. 在这里我想找到实际上已被推送/签出的分支。 I am only interested if its the master, if not i don't wanna do anything. 我只对它的主人感兴趣,否则我什么都不想要。 else i need the list of the pushed files. 否则我需要推送文件的列表。

First the program looked like this : 首先,程序如下所示:

    head = repo.resolve(Constants.HEAD);
        RevCommit commit = rw.parseCommit(head);

        PersonIdent committerIdent = commit.getCommitterIdent();
        sCommitter = committerIdent.getName();

        String sBranch = "?";

        for (Map.Entry<String, Ref> e : repo.getAllRefs().entrySet()) {
            if (e.getKey().startsWith(Constants.R_HEADS)) {
                Ref ref = e.getValue();
                if (rw.isMergedInto(commit, rw.parseCommit(ref.getObjectId()))) {
                    sTemp = ref.getName();

                    int i = sTemp.lastIndexOf('/');
                    if (i == -1)
                        continue;

                    sBranch = sTemp.substring(i + 1);

                    System.out.println("Ref " + sBranch 
                            + " < contains > " + commit);

                    if (sBranch.equalsIgnoreCase("master")) {
                        break;
                    } else {
                        return;
                    }
                }
            }
        }

        RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
        DiffFormatter df = new DiffFormatter(
                DisabledOutputStream.INSTANCE);
        df.setRepository(repo);
        df.setDiffComparator(RawTextComparator.DEFAULT);
        df.setDetectRenames(true);
        List<DiffEntry> diffs = df.scan(parent.getTree(),
                commit.getTree());
        for (DiffEntry diff : diffs) {
            sTemp = diff.getNewPath();
            pushedObjects.add(sTemp);
        }

now .. this works as long as the workflow in eclipse is just "checkout master" "pull" "merge branch" "push" 现在..只要eclipse中的工作流只是“ checkout master”“ pull”“ merge branch”“ push”

any other order seems to mess with the order of the branches in the set, and it stumbles over this "else" : 任何其他顺序似乎都弄乱了集合中分支的顺序,并且绊倒了这个“ else”:

if (sBranch.equalsIgnoreCase("master")) {
      break;
 } else {
      return;
 }

the question is : is there an eaasy method to pick the right branch? 问题是:是否有简便的方法来选择正确的分支?

Ok, i think i can simply look at the HEAD in the set: 好的,我想我可以简单地看一下集合中的HEAD:

e.getKey().startsWith(Constants.HEAD)

and then parse the branchname, that should always be the branch which is checked out, if (in my case),if it is the master, i am happy. 然后解析分支名称,该分支名称应该始终是签出的分支,如果(在我的情况下)如果是主节点,我很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM