Giter Club home page Giter Club logo

go-gitlog's Introduction

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{
		Bin:  "/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

go-gitlog's People

Contributors

wadackel avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.