restack

package module
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 13 Imported by: 0

README

Go

restack augments the experience of performing an interactive Git rebase to make it more friendly to workflows that involve lots of interdependent branches. For more background on why this exists and the workflow it facilitates, see Automatically Restacking Git Branches.

Installation

Binaries

Pre-build binaries for Linux, macOS, and Windows are available at https://github.com/abhinav/restack/releases. To install, simply unpack the archive and put the binaries somewhere on your $PATH.

For example, if you have $HOME/bin on your $PATH,

OS=$(uname -s)
ARCH=$(uname -m)
VERSION=0.5.1
URL="https://github.com/abhinav/restack/releases/download/v$VERSION/restack_${VERSION}_${OS}_${ARCH}.tar.gz"
curl -L "$URL" | tar xzv -C ~/bin restack

Alternatively, if you use Homebrew or Linuxbrew, run the following command.

brew install abhinav/tap/restack

Build From Source

If you have Go installed, you can install restack using the following command.

$ go install github.com/abhinav/restack/cmd/restack@latest

Setup

Automatic Setup

Run restack setup to configure git to use restack.

$ restack setup

Manual Setup

If you would rather not have restack change your .gitconfig, you can set restack up manually.

Point your sequence.editor git configuration to the script generated by restack setup --print-edit-script.

$ restack setup --print-edit-script > bin/restack-edit.sh
$ chmod +x bin/restack-edit.sh
$ git config sequence.editor restack-edit.sh

The generated script will rely on the restack edit command if available, falling back to your GIT_EDITOR if not.

You can also bypass the checks performed by the script and point sequence.editor to the restack edit command directly.

$ git config sequence.editor 'restack edit'

See restack edit --help for the different options accepted by restack edit.

Usage

restack automatically recognizes branches being touched by the rebase and adds rebase instructions which update these branches as their heads move.

The generated instruction list also includes an opt-in commented-out section that will push these branches to the remote.

For example, given,

o master
 \
  o A
  |
  o B (feature1)
   \
    o C
    |
    o D (feature2)
     \
      o E
      |
      o F
      |
      o G (feature3)
       \
        o H (feature4, HEAD)

Running git rebase -i master from branch feature4 will give you the following instruction list.

pick A
pick B
exec git branch -f feature1

pick C
pick D
exec git branch -f feature2

pick E
pick F
pick G
exec git branch -f feature3

pick H

# Uncomment this section to push the changes.
# exec git push -f origin feature1
# exec git push -f origin feature2
# exec git push -f origin feature3

So any changes made before each exec git branch -f will become part of that branch and all following changes will be made on top of that.

Credits

Thanks to @kriskowal for the initial implementation of this tool as a script.

Documentation

Index

Constants

View Source
const Version = "0.5.1"

Version is the version of restack currently being used.

Note that semantic versioning in this repository applies to the `restack` executable, not to its library components. These APIs may break at any time without warning.

Variables

This section is empty.

Functions

This section is empty.

Types

type Branch added in v0.3.0

type Branch struct {
	Name string
	Hash string
}

Branch refers to a Git branch.

type Edit added in v0.3.0

type Edit struct {
	// Editor to use for the file.
	Editor string

	// Path to file containing initial rebase instruction list.
	Path string

	Restacker Restacker

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

Edit implements the "restack edit" command.

func (*Edit) Run added in v0.3.0

func (e *Edit) Run(ctx context.Context) (err error)

Run runs the "restack edit" command.

type Git

type Git interface {
	ListBranches(ctx context.Context) ([]Branch, error)

	// RebaseHeadName returns the name of the branch being rebased or an empty
	// string if we're not in the middle of a rebase.
	RebaseHeadName(ctx context.Context) (string, error)
}

Git provides access to git commands.

type GitRestacker added in v0.3.0

type GitRestacker struct {
	// Controls access to Git commands.
	//
	// This field is required.
	Git Git
}

GitRestacker restacks instruction lists using the provided Git instance.

func (*GitRestacker) Restack added in v0.3.0

func (r *GitRestacker) Restack(ctx context.Context, req *Request) error

Restack process the provided instruction list.

type Request added in v0.3.0

type Request struct {
	// Name of the git remote. If set, an opt-in section that pushes restacked
	// branches to this remote will also be generated.
	//
	// This field is optional.
	RemoteName string

	// Input and output instruction lists.
	From io.Reader
	To   io.Writer
}

Request is a request to process a rebase instruction list.

type Restacker

type Restacker interface {
	Restack(context.Context, *Request) error
}

Restacker processes the rebase instruction list.

type Setup added in v0.3.0

type Setup struct {
	PrintScript bool

	Stdout io.Writer
	Stderr io.Writer
}

Setup is the "restack setup" command.

func (*Setup) Run added in v0.3.0

func (s *Setup) Run(ctx context.Context) error

Run runs the setup command.

type SystemGit

type SystemGit struct {
	Getenv func(string) string
}

SystemGit uses the global `git` command to perform git operations.

func (*SystemGit) ListBranches added in v0.3.0

func (*SystemGit) ListBranches(ctx context.Context) ([]Branch, error)

ListBranches implements Git.ListBranches.

func (*SystemGit) RebaseHeadName

func (g *SystemGit) RebaseHeadName(ctx context.Context) (string, error)

RebaseHeadName implements Git.RebaseHeadName.

Directories

Path Synopsis
cmd
restack
See https://github.com/abhinav/restack#readme.
See https://github.com/abhinav/restack#readme.
internal
editorfake
Package editorfake provides a means of building a configurable fake editor executable.
Package editorfake provides a means of building a configurable fake editor executable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL