Class GitFlow

java.lang.Object
io.github.jbastgen.stemma.gitflow.GitFlow

public final class GitFlow extends Object
The Git Flow branching model on top of a GitRepository: start and finish features, releases and hotfixes, with the same rules as the git flow command line tool.

Finishing is built from idempotent steps (merge, tag, back-merge, delete). If a merge stops on conflicts it stays in progress so it can be resolved with the normal commit workflow; calling finish(io.github.jbastgen.stemma.gitflow.Kind, java.lang.String, io.github.jbastgen.stemma.gitflow.FinishOptions) again then skips what is done and completes the rest.

  • Constructor Details

    • GitFlow

      public GitFlow(io.github.jbastgen.stemma.git.api.GitRepository repo)
      Parameters:
      repo - the repository to work on; it stays open and is not closed here
  • Method Details

    • config

      public GitFlowConfig config()
      The effective configuration: gitflow.* keys, with conventional defaults for what is not set.
    • isInitialized

      public boolean isInitialized()
      Whether both long-lived branches exist, so features, releases and hotfixes can be started.
    • planInitialize

      public GitFlowPlanner.Plan planInitialize(GitFlowConfig config, boolean initialCommit)
      What initialize(io.github.jbastgen.stemma.gitflow.GitFlowConfig) would do with this configuration, and what is wrong with it; reads the repository, changes nothing.
    • facts

      public GitFlowPlanner.Facts facts(GitFlowConfig config)
      What the repository looks like for the plan: branches, remote branches, commits and the keys written now.
    • initialize

      public void initialize(GitFlowConfig config)
      Sets Git Flow up: stores the configuration and creates the development branch from the production branch if it does not exist yet. Safe to call on an initialised repository.
    • initializeNew

      public void initializeNew(GitFlowConfig config, String initialMessage)
      Sets Git Flow up in a repository that has no commit yet (a new one): branches cannot exist before the first commit, so an empty initial commit is made on the production branch, the development branch is created from it, the configuration is stored and the development branch is checked out. In a repository that already has commits it does what initialize(io.github.jbastgen.stemma.gitflow.GitFlowConfig) does and leaves the checked-out branch alone.
      Parameters:
      initialMessage - the message of the initial commit
      Throws:
      io.github.jbastgen.stemma.git.api.GitException - if the repository is still on another branch than the production branch
    • openBranches

      public List<String> openBranches(Kind kind)
      Names of the existing local branches of this kind, sorted, with their prefix.
    • kindOf

      public Optional<Kind> kindOf(String branch)
      The kind of a branch name, judged by its prefix.
    • start

      public String start(Kind kind, String name)
      Starts a feature, release or hotfix and switches to its new branch.
      Parameters:
      name - feature name or version number, without the prefix
      Returns:
      the name of the new branch
      Throws:
      io.github.jbastgen.stemma.git.api.GitException - if a precondition is not met (the message says which)
    • finish

      public FinishResult finish(Kind kind, String name, FinishOptions options)
      Finishes the branch <prefix><name> of the given kind.