gitlog

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2018 License: MIT Imports: 11 Imported by: 0

README

go-gitlog

godoc.org Travis MIT License

Go (golang) package for providing a means to handle git-log.

Installation

To install go-gitlog, simply run:

$ go get -u github.com/tsuyoshiwada/go-gitlog

Usage

It is the simplest example.

package main

import (
	"log"
	"github.com/tsuyoshiwada/go-gitlog"
)

func main() {
	// New gitlog
	git := gitlog.New(&gitlog.Config{
		GitBin: "/your/custom/git/bin", // default "git"
		Path: "/repo/path/to",          // default "."
	})

	// List git-log
	commits, err := git.Log(nil, nil)
	if err != nil {
		log.Fatalln(err)
	}

	// Output
	for _, commit := range commits {
		fmt.Printf(
			"%s %s %s\n",
			commit.Hash.Short,
			commit.Author.Name,
			commit.Subject,
		)
	}
}

See godoc for API detail of Log 👍

Options

By using Params you can customize the log retrieval.

MergesOnly

Give the --merges option.

IgnoreMerges

Give the --no-merges option.

Reverse

Give the --reverse option.

Examples

$ git log <sha1|tag|ref>

Specification of revisionrange can be realized by giving a RevArgs interface.

commits, err := git.Log(&gitlog.Rev{"5e312d5"}, nil)
$ git log <sha1|tag|ref>..<sha1|tag|ref>

For double dot notation use RevRange.

commits, err := git.Log(&gitlog.RevRange{
	Old: "v0.1.7",
	New: "v1.2.3",
}, nil)
$ git log -n <n>

Use RevNumber to get the specified number of commits.

commits, err := git.Log(&gitlog.RevNumber{10}, nil)
$ git log --since <time> --until <time>

By using RevTime you can specify the range by time.

Since and Until:

commits, err := git.Log(&gitlog.RevTime{
	Since: time.Date(2018, 3, 4, 23, 0, 0, time.UTC),
	Until: time.Date(2018, 1, 2, 12, 0, 0, time.UTC),
}, nil)

Only since:

commits, err := git.Log(&gitlog.RevTime{
	Since: time.Date(2018, 1, 2, 12, 0, 0, time.UTC),
}, nil)

Only until:

commits, err := git.Log(&gitlog.RevTime{
	Until: time.Date(2018, 1, 2, 12, 0, 0, time.UTC),
}, nil)

How it works

Internally we use the git command to format it with the --pretty option of log and parse the standard output.
So, only local git repositories are eligible for acquisition.

Contribute

  1. Fork (https://github.com/tsuyoshiwada/go-gitlog)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test command and confirm that it passes
  6. Create new Pull Request 💪

Bugs, feature requests and comments are more than welcome in the issues.

License

MIT © tsuyoshiwada

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct {
	Name  string
	Email string
	Date  time.Time
}

Author of commit

type Commit

type Commit struct {
	Hash      *Hash
	Tree      *Tree
	Author    *Author
	Committer *Committer
	Subject   string
	Body      string
}

Commit data

type Committer

type Committer struct {
	Name  string
	Email string
	Date  time.Time
}

Committer of commit

type Config

type Config struct {
	GitBin string // default "git"
	Path   string // default "."
}

Config for getting git-log

type GitLog

type GitLog interface {
	Log(RevArgs, *Params) ([]*Commit, error)
}

GitLog is an interface for git-log acquisition

func New

func New(config *Config) GitLog

New GitLog interface

type Hash

type Hash struct {
	Long  string
	Short string
}

Hash of commit

type Params

type Params struct {
	MergesOnly   bool
	IgnoreMerges bool
	Reverse      bool
}

Params for getting git-log

type Rev

type Rev struct {
	Ref string
}

Rev is useful for specifying refname

func (*Rev) Args

func (rev *Rev) Args() []string

Args ...

type RevAll

type RevAll struct{}

RevAll alias for `--all`

func (*RevAll) Args

func (*RevAll) Args() []string

Args ...

type RevArgs

type RevArgs interface {
	Args() []string
}

RevArgs is used to specify the range of git-log

type RevNumber

type RevNumber struct {
	Limit int
}

RevNumber alias for `-n <number>`

func (*RevNumber) Args

func (rev *RevNumber) Args() []string

Args ...

type RevRange

type RevRange struct {
	New string
	Old string
}

RevRange is useful for specifying refname range alias for `<ref>..<ref>`

func (*RevRange) Args

func (rev *RevRange) Args() []string

Args ...

type RevTime

type RevTime struct {
	Since time.Time
	Until time.Time
}

RevTime alias for `--since <date> --until <date>`

func (*RevTime) Args

func (rev *RevTime) Args() []string

Args ...

type Tree

type Tree struct {
	Long  string
	Short string
}

Tree hash of commit

Jump to

Keyboard shortcuts

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