Class: Git::Commands::Branch::Move Private

Inherits:
Git::Commands::Base show all
Defined in:
lib/git/commands/branch/move.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

arguments block audited against https://git-scm.com/docs/git-branch/2.53.0

Implements the git branch --move command for renaming branches

This command moves/renames a branch, together with its config and reflog. If the old branch name is omitted, renames the current branch.

Examples:

Rename the current branch

move = Git::Commands::Branch::Move.new(execution_context)
move.call('new-branch-name')

Rename a specific branch

move = Git::Commands::Branch::Move.new(execution_context)
move.call('old-branch-name', 'new-branch-name')

Force rename (overwrite existing branch)

move = Git::Commands::Branch::Move.new(execution_context)
move.call('old-branch', 'existing-branch', force: true)

See Also:

Instance Method Summary collapse

Methods inherited from Git::Commands::Base

allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation

Constructor Details

This class inherits a constructor from Git::Commands::Base

Instance Method Details

#call(new_branch, **options) ⇒ Git::CommandLineResult #call(old_branch, new_branch, **options) ⇒ Git::CommandLineResult

Execute the git branch --move command to rename a branch

Overloads:

  • #call(new_branch, **options) ⇒ Git::CommandLineResult

    Rename the current branch to new_branch

    Parameters:

    • new_branch (String)

      the new name for the branch

    • options (Hash)

      command options

    Options Hash (**options):

    • :force (Boolean, nil) — default: nil

      allow renaming even if new_branch already exists

      Alias: :f

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits with a non-zero exit status

  • #call(old_branch, new_branch, **options) ⇒ Git::CommandLineResult

    Rename old_branch to new_branch

    Parameters:

    • old_branch (String)

      the current name of the branch

    • new_branch (String)

      the new name for the branch

    • options (Hash)

      command options

    Options Hash (**options):

    • :force (Boolean, nil) — default: nil

      allow renaming even if new_branch already exists

      Alias: :f

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits with a non-zero exit status



# File 'lib/git/commands/branch/move.rb', line 50