restack

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 10 Imported by: 0

README

Build Status

restack augments the experience of performing an interactive Git rebase to make it more friendly to workflows that involve lots of interdependent branches.

Installation

Binaries

Pre-built ARM and 64-bit binaries are available for Linux and Mac 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=$(go env GOOS)
ARCH=$(go env GOARCH)
VERSION=v0.1.2
URL="https://github.com/abhinav/restack/releases/download/$VERSION/restack.$VERSION.$OS.$ARCH.tar.gz"
curl -L "$URL" | tar xzv -C ~/bin

Build From Source

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

$ go get -u github.com/abhinav/restack/cmd/restack

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.1.2"

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 FS

type FS interface {
	// Returns true if a file exists at the provided path.
	FileExists(path string) bool

	// MkdirAll creates a directory at the provided path and any needed parent
	// directories.
	//
	// See os.MkdirAll.
	MkdirAll(path string) error

	// Starts reading the file at the provided path.
	//
	// See os.Open.
	ReadFile(path string) (io.ReadCloser, error)

	// Starts writing to the file at the given path, truncating it if it
	// already exists.
	//
	// See os.Create.
	WriteFile(path string) (io.WriteCloser, error)

	// Start writing to the file at the given path, truncating it if it
	// already exists. The file will be created with permissions 0755.
	//
	// See os.OpenFile.
	WriteExecutableFile(path string) (io.WriteCloser, error)

	// Renames old to new.
	//
	// See os.Rename.
	Rename(old, new string) error

	// Creates a temporary directory somewhere on the system and returns an
	// absolute path to it.
	//
	// It's the caller's responsibility to clean this directory up.
	TempDir(prefix string) (string, error)

	// RemoveAll removes the file/directory at the given path and if it's a
	// directory, all its descendants.
	//
	// See os.RemoveAll.
	RemoveAll(path string) error
}

FS provides access to the filesystem.

var DefaultFilesystem FS = defaultFS{}

DefaultFilesystem is the real underlying filesystem.

type Git

type Git interface {
	// Changes the global configuration for the given key.
	//
	// Equivalent to,
	//
	//   git config --global $name $value
	SetGlobalConfig(ctx context.Context, name, value string) error

	// Returns a mapping from abbreviated hash to list of refs at that hash.
	ListHeads(ctx context.Context) (map[string][]string, 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 Restacker

type Restacker 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

	// Controls access to Git commands.
	//
	// This field is required.
	Git Git
}

Restacker reads the todo list of an interactive rebase and writes a new version of it with the provided configuration.

func (Restacker) Run

func (r Restacker) Run(ctx context.Context, dst io.Writer, src io.Reader) error

Run reads rebase instructions from src and writes them to dst based on the Restacker configuration.

type SystemGit

type SystemGit struct {
	// contains filtered or unexported fields
}

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

func NewSystemGit

func NewSystemGit(fs FS) *SystemGit

NewSystemGit builds a new SystemGit.

The provides FS is used for file-system operations.

func (*SystemGit) ListHeads

func (*SystemGit) ListHeads(ctx context.Context) (map[string][]string, error)

ListHeads implements Git.ListHeads.

func (*SystemGit) RebaseHeadName

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

RebaseHeadName implements Git.RebaseHeadName.

func (*SystemGit) SetGlobalConfig

func (*SystemGit) SetGlobalConfig(ctx context.Context, name, value string) error

SetGlobalConfig implements Git.SetGlobalConfig.

Directories

Path Synopsis
cmd
restack command
See https://github.com/abhinav/restack#readme.
See https://github.com/abhinav/restack#readme.

Jump to

Keyboard shortcuts

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