git

package
v0.0.0-...-eedcae6 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2015 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package git contains various commands that shell out to git

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	proto.ServerInfo
	*Git
}

Bar git configuration

func NewConfig

func NewConfig(info proto.ServerInfo, g *Git) *Config

func (*Config) Install

func (c *Config) Install(logLevel string) (err error)

func (*Config) Uninstall

func (c *Config) Uninstall() (err error)

type DiffEntry

type DiffEntry struct {

	// Git OID to get cached manifest
	OID string

	// bar BLOB ID
	ID string

	// BLOB filename
	Filename string
}

Extracted diff entry

type Divert

type Divert struct {
	*Git
}

Divert is ability to temporary switch branch preserving all blobs in working tree.

# Reset index and HEAD to otherbranch
git reset otherbranch

# make commit for otherbranch
git add file-to-commit
git commit "edited file"

# force recreate otherbranch to here
git branch -f otherbranch

# Go back to where we were before
# (two commits ago, the reset and the commit)
git reset HEAD@{2}

func NewDivert

func NewDivert(host *Git) *Divert

Make new divert on existing git repo

func (*Divert) Begin

func (d *Divert) Begin(spec DivertSpec) (err error)

Begin diversion to on branch where "names" is git-specific <tree-ish>

func (*Divert) CleanSpec

func (d *Divert) CleanSpec() (err error)

func (*Divert) Cleanup

func (d *Divert) Cleanup(spec DivertSpec) (err error)

Abort diversion

func (*Divert) Commit

func (d *Divert) Commit(spec DivertSpec, message string) (err error)

Finish diversion.

func (*Divert) IsInProgress

func (d *Divert) IsInProgress() (res bool, err error)

Is divert in progress

func (*Divert) PrepareBegin

func (d *Divert) PrepareBegin(branch string, names ...string) (res DivertSpec, err error)

Consistency checks before begin diversion and return spec

func (*Divert) ReadSpec

func (d *Divert) ReadSpec() (res DivertSpec, err error)

type DivertSpec

type DivertSpec struct {
	// Home ref
	Head string

	// Replaced files
	ToRecover []string

	// Target branch
	TargetBranch string

	// Target files
	TargetFiles []string
}

Diversion spec

type Git

type Git struct {
	*lists.Mapper
}

Git wrapper. TODO: use native git (https://github.com/gogits/git)

This wrapper always run git in repository root

func NewGit

func NewGit(cwd string) (res *Git, err error)

New git in given root.

func (*Git) Add

func (g *Git) Add(filenames ...string) (err error)

func (*Git) BranchRecreate

func (g *Git) BranchRecreate(branch string) (err error)

git branch -f <branch>

func (*Git) Cat

func (g *Git) Cat(oid string) (res io.Reader, err error)

Cat file from index

$ git cat-file -p <OID>

func (*Git) Checkout

func (g *Git) Checkout(what string, filenames ...string) (err error)

func (*Git) CleanHook

func (g *Git) CleanHook(name string) (err error)

func (*Git) Commit

func (g *Git) Commit(message string) (err error)

func (*Git) Diff

func (g *Git) Diff(filenames ...string) (res io.Reader, err error)

Run diff against HEAD

$ git diff --cached --staged --full-index --no-color HEAD

func (*Git) DiffFiles

func (g *Git) DiffFiles(filenames ...string) (res []string, err error)

Get list of non-staged files in working tree

$ git diff-files --name-only

func (*Git) DiffIndex

func (g *Git) DiffIndex(filenames ...string) (res []string, err error)

Get list of non-commited files in staging area

git diff-index HEAD

func (*Git) FilterByAttr

func (g *Git) FilterByAttr(diff string, filenames ...string) (res []string, err error)

Filter files by diff attribute

$ git check-attr diff <files> | grep "diff: <diff>"

This command takes and returns filenames relative to CWD

func (*Git) GetBranches

func (g *Git) GetBranches() (current string, other []string, err error)

func (*Git) GetHook

func (g *Git) GetHook(name string) (res string, err error)

Get git hook contents

func (*Git) GetOID

func (g *Git) GetOID(filename string) (res string, err error)

Get file OID in Git index

$ git ls-files --cached -s --full-name <file>

func (*Git) GetRevParse

func (g *Git) GetRevParse(what string) (res string, err error)

func (*Git) LsTree

func (g *Git) LsTree(what string, paths ...string) (res []string, err error)

func (*Git) ManifestsFromDiff

func (g *Git) ManifestsFromDiff(r io.Reader) (res lists.BlobMap, err error)

Extract manifests from diff

$ git diff --staged --cached -U99999999999999 --no-prefix
diff --git fix/aa.txt fix/aa.txt
index 5afd5028d71cfadf73c0e3abd70f852d67357909..63c202a03152c8635eb78dcfef35859f0c68f5cf 100644
--- fix/aa.txt
+++ fix/aa.txt
@@ -1,10 +1,10 @@
 BAR:MANIFEST

-id aba7aeb8a7948dd0cdb8eeb9239e5d1dab2bd840f13930f86f6e67ba40ea5350
-size 4
+id f627c8f9355399ef45e1a6b6e5a9e6a3abcb3e1b6255603357bffa9f2211ba7e
+size 6

-id aba7aeb8a7948dd0cdb8eeb9239e5d1dab2bd840f13930f86f6e67ba40ea5350
-size 4
+id f627c8f9355399ef45e1a6b6e5a9e6a3abcb3e1b6255603357bffa9f2211ba7e
+size 6
 offset 0

	...

diff --git fix/aa2.txt fix/aa2.txt
new file mode 100644
index 0000000000000000000000000000000000000000..63c202a03152c8635eb78dcfef35859f0c68f5cf
--- /dev/null
+++ fix/aa2.txt         <--- Start consuming
@@ -0,0 +1,10 @@        <--- if consuming - next line
+BAR:MANIFEST           <--- Start consuming manifest by "" and "+"
+
+id f627c8f9355399ef45e1a6b6e5a9e6a3abcb3e1b6255603357bffa9f2211ba7e
+size 6
+
+
+id f627c8f9355399ef45e1a6b6e5a9e6a3abcb3e1b6255603357bffa9f2211ba7e
+size 6
+offset 0
+

func (*Git) Push

func (g *Git) Push(upstream, branch string) (err error)

func (*Git) Reset

func (g *Git) Reset(to string) (err error)

func (*Git) Run

func (g *Git) Run(sub string, arg ...string) (res string, err error)

Run git command

func (*Git) SetConfig

func (g *Git) SetConfig(key, val string) (err error)

Set config value

func (*Git) SetHook

func (g *Git) SetHook(name string, contents string) (err error)

Install git hook

func (*Git) UnsetConfig

func (g *Git) UnsetConfig(key string) (err error)

Unset config value

func (*Git) UpdateIndex

func (g *Git) UpdateIndex(what ...string) (err error)

Refresh files in git index (use after squash or blow)

Jump to

Keyboard shortcuts

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