Class MergeStrategy

java.lang.Object
org.eclipse.jgit.merge.MergeStrategy
Direct Known Subclasses:
StrategyOneSided, ThreeWayMergeStrategy

public abstract class MergeStrategy extends Object
A method of combining two or more trees together to form an output tree.

Different strategies may employ different techniques for deciding which paths (and ObjectIds) to carry from the input trees into the final output tree.

  • Field Details

    • OURS

      public static final MergeStrategy OURS
      Simple strategy that sets the output tree to the first input tree.
    • THEIRS

      public static final MergeStrategy THEIRS
      Simple strategy that sets the output tree to the second input tree.
    • SIMPLE_TWO_WAY_IN_CORE

      public static final ThreeWayMergeStrategy SIMPLE_TWO_WAY_IN_CORE
      Simple strategy to merge paths, without simultaneous edits.
    • RESOLVE

      public static final ThreeWayMergeStrategy RESOLVE
      Simple strategy to merge paths. It tries to merge also contents. Multiple merge bases are not supported
    • RECURSIVE

      public static final ThreeWayMergeStrategy RECURSIVE
      Recursive strategy to merge paths. It tries to merge also contents. Multiple merge bases are supported
      Since:
      3.0
    • STRATEGIES

      private static final HashMap<String,MergeStrategy> STRATEGIES
  • Constructor Details

    • MergeStrategy

      public MergeStrategy()
  • Method Details

    • register

      public static void register(MergeStrategy imp)
      Register a merge strategy so it can later be obtained by name.
      Parameters:
      imp - the strategy to register.
      Throws:
      IllegalArgumentException - a strategy by the same name has already been registered.
    • register

      public static void register(String name, MergeStrategy imp)
      Register a merge strategy so it can later be obtained by name.
      Parameters:
      name - name the strategy can be looked up under.
      imp - the strategy to register.
      Throws:
      IllegalArgumentException - a strategy by the same name has already been registered.
    • get

      public static MergeStrategy get(String name)
      Locate a strategy by name.
      Parameters:
      name - name of the strategy to locate.
      Returns:
      the strategy instance; null if no strategy matches the name.
    • get

      public static MergeStrategy[] get()
      Get all registered strategies.
      Returns:
      the registered strategy instances. No inherit order is returned; the caller may modify (and/or sort) the returned array if necessary to obtain a reasonable ordering.
    • getName

      public abstract String getName()
      Get default name of this strategy implementation.
      Returns:
      default name of this strategy implementation.
    • newMerger

      public abstract Merger newMerger(Repository db)
      Create a new merge instance.
      Parameters:
      db - repository database the merger will read from, and eventually write results back to.
      Returns:
      the new merge instance which implements this strategy.
    • newMerger

      public abstract Merger newMerger(Repository db, boolean inCore)
      Create a new merge instance.
      Parameters:
      db - repository database the merger will read from, and eventually write results back to.
      inCore - the merge will happen in memory, working folder will not be modified, in case of a non-trivial merge that requires manual resolution, the merger will fail.
      Returns:
      the new merge instance which implements this strategy.
    • newMerger

      public abstract Merger newMerger(ObjectInserter inserter, Config config)
      Create a new merge instance.

      The merge will happen in memory, working folder will not be modified, in case of a non-trivial merge that requires manual resolution, the merger will fail.

      Parameters:
      inserter - inserter to write results back to.
      config - repo config for reading diff algorithm settings.
      Returns:
      the new merge instance which implements this strategy.
      Since:
      4.8