Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
update git info with branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
zbindenren committed Nov 20, 2019
1 parent dc17bbf commit a60a973
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"fmt"
"html/template"
"io"
"io/ioutil"
Expand All @@ -13,6 +14,8 @@ import (
"reflect"
"testing"
"time"

"github.com/stretchr/testify/require"
)

const testData = "./testdata"
Expand All @@ -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",
Expand Down Expand Up @@ -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)
}
5 changes: 4 additions & 1 deletion git/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
3 changes: 3 additions & 0 deletions git/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand Down

0 comments on commit a60a973

Please sign in to comment.