当前位置: 首页>>代码示例>>Java>>正文


Java MergeCommand类代码示例

本文整理汇总了Java中org.eclipse.jgit.api.MergeCommand的典型用法代码示例。如果您正苦于以下问题:Java MergeCommand类的具体用法?Java MergeCommand怎么用?Java MergeCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MergeCommand类属于org.eclipse.jgit.api包,在下文中一共展示了MergeCommand类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: merge

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
public Pair<Boolean, String> merge(String branchToUpdate, String branchHead, boolean commit) {
    
    Pair<Boolean, String> ret = new Pair<>(false, "");
    MergeCommand command = _git.merge();
    try {
        String refName =
                !branchHead.contains(REFS_HEADS) ? REFS_REMOTES + branchHead : branchHead;
        command.include(_repo.getRef(refName));
        command.setCommit(commit);
        MergeResult mergeResult = command.call();
        ret = checkResult(branchToUpdate, branchHead, ret, mergeResult);
    } catch (Throwable e) {
        VerigreenLogger.get().log(
                getClass().getName(),
                RuntimeUtils.getCurrentMethodName(),
                String.format(
                        "Failed to update branch [%s] with parent branch [%s]",
                        branchToUpdate,
                        branchHead));
    }
    
    return ret;
}
 
开发者ID:Verigreen,项目名称:verigreen,代码行数:24,代码来源:JGitOperator.java

示例2: getDefaultFastForwardOption

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
/**
 * Parses the repository configuration file and returns the default fast-forward merge
 * option set for the repository and its current branch.
 * 
 * @return the default fast-forward option for the current repository and the active branch.
 * @throws GitException an error occurs
 * @since 1.26
 */
public FastForwardOption getDefaultFastForwardOption () throws GitException {
    JGitRepository repository = getRepository();
    repository.increaseClientUsage();
    try {
        MergeConfig cfg = MergeConfig.getConfigForCurrentBranch(repository.getRepository());
        MergeCommand.FastForwardMode mode = cfg.getFastForwardMode();
        switch (mode) {
            case FF_ONLY:
                return FastForwardOption.FAST_FORWARD_ONLY;
            case NO_FF:
                return FastForwardOption.NO_FAST_FORWARD;
            default:
                return FastForwardOption.FAST_FORWARD;
        }
    } finally {
        repository.decreaseClientUsage();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:GitRepository.java

示例3: setupMergeCommand

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
private static void setupMergeCommand(MergeCommand merge, List<Ref> commitsByRef, List<AnyObjectId> commitsById,
                                      List<NamedCommit> commitsByNameAndId, ProgressMonitor monitor,
                                      MergeStrategy strategy, MergeCommand.FastForwardMode fastForwardMode) {
    commitsByRef.forEach(merge::include);
    commitsById.forEach(merge::include);
    commitsByNameAndId.forEach(nc -> merge.include(nc.getName(), nc.getObjectId()));

    if (monitor != null) { merge.setProgressMonitor(monitor); }

    merge
            .setFastForward(fastForwardMode)
            .setStrategy(strategy);
}
 
开发者ID:JordanMartinez,项目名称:JGitFX,代码行数:14,代码来源:GitHelper.java

示例4: mergeWithSquash

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
public static MergeResult mergeWithSquash(Git git, MergeStrategy strategy,  List<Ref> commitsByRef,
                                   List<AnyObjectId> commitsById, List<NamedCommit> commitsByNameAndId,
                                   MergeCommand.FastForwardMode fastForwardMode,
                                   ProgressMonitor monitor) throws GitAPIException {
    MergeCommand merge = git.merge();

    setupMergeCommand(merge, commitsByRef, commitsById, commitsByNameAndId, monitor, strategy, fastForwardMode);

    return merge
            .setStrategy(strategy)
            .setFastForward(fastForwardMode)
            .setSquash(true)
            .call();
}
 
开发者ID:JordanMartinez,项目名称:JGitFX,代码行数:15,代码来源:GitHelper.java

示例5: mergeWithoutCommit

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
public static MergeResult mergeWithoutCommit(Git git, MergeStrategy strategy, List<Ref> commitsByRef,
                                      List<AnyObjectId> commitsById, List<NamedCommit> commitsByNameAndId,
                                      MergeCommand.FastForwardMode fastForwardMode,
                                      ProgressMonitor monitor) throws GitAPIException {
    MergeCommand merge = git.merge();

    setupMergeCommand(merge, commitsByRef, commitsById, commitsByNameAndId, monitor, strategy, fastForwardMode);

    return merge
            .setStrategy(strategy)
            .setFastForward(fastForwardMode)
            .setCommit(false)
            .call();
}
 
开发者ID:JordanMartinez,项目名称:JGitFX,代码行数:15,代码来源:GitHelper.java

示例6: mergeWithCommit

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
public static MergeResult mergeWithCommit(Git git, MergeStrategy strategy, List<Ref> commitsByRef, List<AnyObjectId> commitsById,
                                          List<NamedCommit> commitsByNameAndId, String commitMessage,
                                          MergeCommand.FastForwardMode fastForwardMode,
                                          ProgressMonitor monitor) throws GitAPIException {
    MergeCommand merge = git.merge();

    setupMergeCommand(merge, commitsByRef, commitsById, commitsByNameAndId, monitor, strategy, fastForwardMode);

    return git.merge()
            .setMessage(commitMessage)           // message to be used for merge commit
            .call();
}
 
开发者ID:JordanMartinez,项目名称:JGitFX,代码行数:13,代码来源:GitHelper.java

示例7: updateChanges

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
public void updateChanges(ProgressMonitor monitor) throws Exception {
    Git git = getGit(monitor);

    FetchCommand fetch = git.fetch();
    fetch.setCredentialsProvider(credentialsProvider);
    if (monitor != null)
        fetch.setProgressMonitor(monitor);
    fetch.call();

    SyncState state = getSyncState(git);
    Ref fetchHead = git.getRepository().getRef("FETCH_HEAD");
    switch (state) {
        case Equal:
            // Do nothing
            Log.d("Git", "Local branch is up-to-date");
            break;

        case Ahead:
            Log.d("Git", "Local branch ahead, pushing changes to remote");
            git.push().setCredentialsProvider(credentialsProvider).setRemote(remotePath).call();
            break;

        case Behind:
            Log.d("Git", "Local branch behind, fast forwarding changes");
            MergeResult result = git.merge().include(fetchHead).setFastForward(MergeCommand.FastForwardMode.FF_ONLY).call();
            if (result.getMergeStatus().isSuccessful() == false)
                throw new IllegalStateException("Fast forward failed on behind merge");
            break;

        case Diverged:
            Log.d("Git", "Branches are diverged, merging with strategy " + mergeStrategy.getName());
            MergeResult mergeResult = git.merge().include(fetchHead).setStrategy(mergeStrategy).call();
            if (mergeResult.getMergeStatus().isSuccessful()) {
                git.push().setCredentialsProvider(credentialsProvider).setRemote(remotePath).call();
            } else
                throw new IllegalStateException("Merge failed for diverged branches using strategy " + mergeStrategy.getName());
            break;
    }
}
 
开发者ID:hdweiss,项目名称:mOrgAnd,代码行数:40,代码来源:JGitWrapper.java

示例8: doExecute

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
@Override
public void doExecute() {
        try {
                MergeCommand mergeCommand = git.merge().setSquash(squash);
                mergeCommand.include(mergeCommand.getRepository().getRef(branchname));

                setupCredentials(mergeCommand);

                MergeResult mergeResult = null;
                try {
                        mergeResult = mergeCommand.call();
                } catch (CheckoutConflictException conflicts) {
                        throw new BuildException(String.format("%s - Checkout conflicts: %s", MESSAGE_MERGE_FAILED, conflicts.getConflictingPaths()));
                }

                if (!mergeResult.getMergeStatus().isSuccessful()) {

                        if (mergeResult.getCheckoutConflicts() != null && mergeResult.getCheckoutConflicts().size() > 0) {
                                throw new BuildException(String.format("%s - Checkout conflicts: %s", MESSAGE_MERGE_FAILED, mergeResult.getCheckoutConflicts()));
                        }

                        if (mergeResult.getFailingPaths() != null && mergeResult.getFailingPaths().size() > 0) {
                                throw new BuildException(String.format("%s - Failing paths: %s", MESSAGE_MERGE_FAILED, mergeResult.getFailingPaths()));
                        }

                        throw new BuildException(String.format(MESSAGE_MERGE_FAILED_WITH_STATUS, mergeResult.getMergeStatus().name()));
                }
        } catch (Exception e) {
                throw new GitBuildException(String.format(MESSAGE_MERGE_FAILED_WITH_URI, getUri()), e);
        }
}
 
开发者ID:rimerosolutions,项目名称:ant-git-tasks,代码行数:32,代码来源:MergeTask.java

示例9: testMergeSelectedBranchWithCurrent

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
@Test
public void testMergeSelectedBranchWithCurrent() throws Exception {
    // first fetch from remote
    RefSpec fetchSpec = new RefSpec
            ("+refs/heads/*:refs/remotes/origin/*");
    new Git(helper.getRepo()).fetch().setRefSpecs(fetchSpec).call();

    // start tracking the remote branch "random"
    new Git(helper.getRepo()).checkout().
            setCreateBranch(true).
            setForce(true).
            setName("random").
            setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
            setStartPoint("origin/random").
            call();

    // make changes to local file and commit
    File file = Paths.get(this.repoPath.toString(), "test.txt").toFile();
    assertTrue(file.exists());

    try(PrintWriter fileTextWriter = new PrintWriter( file )){
        fileTextWriter.println("Add a line to the file");
    }

    this.helper.addFilePathTest(file.toPath());
    this.helper.commit("Modified test.txt in a unit test!");

    new Git(helper.getRepo()).checkout().setName("master").call();

    // merge master into random
    MergeCommand merge = new Git(helper.getRepo()).merge();
    merge.include(helper.getRepo().resolve("refs/heads/random"));

    MergeResult mergeResult = merge.call();
    assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.FAST_FORWARD);

    // TODO: fix this if you ever run it
    //CommitTreeController.update(helper);

    // after update, should expect the heads of two branches
    // are the same commit
    helper.getBranchModel().updateLocalBranches();
    assertEquals(helper.getBranchModel().getBranchListTyped(BranchModel.BranchType.LOCAL).size(), 2);

    String masterHead = helper.getBranchModel().getBranchListTyped(BranchModel.BranchType.LOCAL).get(0).getHeadId().getName();
    String randomHead = helper.getBranchModel().getBranchListTyped(BranchModel.BranchType.LOCAL).get(1).getHeadId().getName();

    assertEquals(masterHead, randomHead);
}
 
开发者ID:dmusican,项目名称:Elegit,代码行数:50,代码来源:BranchManagerUiUpdateTest.java

示例10: main

import org.eclipse.jgit.api.MergeCommand; //导入依赖的package包/类
public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.createNewRepository()) {
        try (Git git = new Git(repository)) {
            // create some commit on master
            createCommit(repository, git, "masterFile", "content12");

            // create branch "changes"
            Ref changes = git.branchCreate().setName("changes").call();
            System.out.println("Result of creating the branch: " + changes);

            // now start a change on master
            createCommit(repository, git, "sharedFile", "content12");

            // check out branch "changes"
            Ref checkout = git.checkout().setName("changes").call();
            System.out.println("Result of checking out the branch: " + checkout);

            // create some commit on branch "changes", one of them conflicting with the change on master
            createCommit(repository, git, "branchFile", "content98");
            createCommit(repository, git, "sharedFile", "content98");

            // check out "master"
            checkout = git.checkout().setName("master").call();
            System.out.println("Result of checking out master: " + checkout);

            // retrieve the objectId of the latest commit on branch
            ObjectId mergeBase = repository.resolve("changes");

            // perform the actual merge, here we disable FastForward to see the
            // actual merge-commit even though the merge is trivial
            MergeResult merge = git.merge().
                    include(mergeBase).
                    setCommit(true).
                    setFastForward(MergeCommand.FastForwardMode.NO_FF).
                    //setSquash(false).
                    setMessage("Merged changes").
                    call();
            System.out.println("Merge-Results for id: " + mergeBase + ": " + merge);
            for (Map.Entry<String,int[][]> entry : merge.getConflicts().entrySet()) {
                System.out.println("Key: " + entry.getKey());
                for(int[] arr : entry.getValue()) {
                    System.out.println("value: " + Arrays.toString(arr));
                }
            }
        }
    }
}
 
开发者ID:centic9,项目名称:jgit-cookbook,代码行数:48,代码来源:MergeChanges.java


注:本文中的org.eclipse.jgit.api.MergeCommand类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。