From a60a973157217931e66e5d5a6f0837dd3cd2c6c2 Mon Sep 17 00:00:00 2001 From: Rene Zbinden Date: Wed, 20 Nov 2019 16:53:00 +0100 Subject: [PATCH] update git info with branch name --- git/git.go | 2 ++ git/git_test.go | 9 +++++++++ git/go.mod | 5 ++++- git/go.sum | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/git/git.go b/git/git.go index b9e4206..68e8c3a 100644 --- a/git/git.go +++ b/git/git.go @@ -30,6 +30,7 @@ type Info struct { // Commit contains all revision information. type Commit struct { Hash string + Name string ShortHash string Timestamp time.Time Author author @@ -110,6 +111,7 @@ func New(path string, opts ...func(*Info)) (*Info, error) { } i.Dirty = d i.Commit.Hash = ref.Hash().String() + i.Commit.Name = string(ref.Name()) i.Commit.ShortHash = i.Commit.Hash[:8] i.Commit.Author.Name = auth.Name i.Commit.Author.Email = auth.Email diff --git a/git/git_test.go b/git/git_test.go index c5eeb7c..716ec0d 100644 --- a/git/git_test.go +++ b/git/git_test.go @@ -4,6 +4,7 @@ import ( "archive/tar" "bytes" "compress/gzip" + "fmt" "html/template" "io" "io/ioutil" @@ -13,6 +14,8 @@ import ( "reflect" "testing" "time" + + "github.com/stretchr/testify/require" ) const testData = "./testdata" @@ -32,6 +35,7 @@ func TestNotag(t *testing.T) { Hash: "6ea1790235210db239ddb8b6d0191db571f5bd64", ShortHash: "6ea17902", Timestamp: time.Time{}, + Name: "refs/heads/master", Author: author{ Name: "Rene Zbinden", Email: "rene.zbinden@postfinance.ch", @@ -307,5 +311,10 @@ func TestTemplates(t *testing.T) { } }) } +} +func TestRene(t *testing.T) { + i, err := New("/tmp/tag") + require.NoError(t, err) + fmt.Println(i.Commit.Name) } diff --git a/git/go.mod b/git/go.mod index 07c10c2..d632d83 100644 --- a/git/go.mod +++ b/git/go.mod @@ -2,4 +2,7 @@ module github.com/postfinance/mage/git go 1.12 -require gopkg.in/src-d/go-git.v4 v4.10.0 +require ( + github.com/stretchr/testify v1.2.2 + gopkg.in/src-d/go-git.v4 v4.10.0 +) diff --git a/git/go.sum b/git/go.sum index 0a0324f..1248ceb 100644 --- a/git/go.sum +++ b/git/go.sum @@ -1,5 +1,6 @@ github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emirpasic/gods v1.9.0 h1:rUF4PuzEjMChMiNsVjdI+SyLu7rEqpQ5reNFnhC7oFo= github.com/emirpasic/gods v1.9.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= @@ -19,11 +20,13 @@ github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk github.com/pelletier/go-buffruneio v0.2.0 h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA= github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/xanzy/ssh-agent v0.2.0 h1:Adglfbi5p9Z0BmK2oKU9nTG+zKfniSfnaMYB+ULd+Ro= github.com/xanzy/ssh-agent v0.2.0/go.mod h1:0NyE30eGUDliuLEHJgYte/zncp2zdTStcOnWhgSqHD8=