@cryptotaxi247 / kubo / commits / e05f2d372

adds the option to see the current git commit with `ipfs version --commit` License: MIT Signed-off-by: Caio Alonso <caio@caioalonso.com>

adds the option to see the current git commit with `ipfs version --commit` License: MIT Signed-off-by: Caio Alonso <caio@caioalonso.com>

Caio Alonso committed Oct 17, 2015 at 19:48 UTC e05f2d3724a3ef74f34ba37d3526f46c2083af8b
4 files changed +23 -4
Makefile
+3 -1
@@ -5,6 +5,8 @@ else
5 go_test=go test
6 endif
7
8 +commit = `git rev-parse --short HEAD`
9 +ldflags = "-X "github.com/ipfs/go-ipfs/repo/config".CurrentCommit=$(commit)"
10
11 all:
12 # no-op. try:
@@ -24,7 +26,7 @@ install:
26 cd cmd/ipfs && go install
27
28 build:
27 - cd cmd/ipfs && go build -i
29 + cd cmd/ipfs && go build -i -ldflags=$(ldflags)
30
31 nofuse:
32 cd cmd/ipfs && go install -tags nofuse
cmd/ipfs/Makefile
+3 -1
@@ -1,7 +1,9 @@
1 all: install
2 +commit = `git rev-parse --short HEAD`
3 +ldflags = "-X "github.com/ipfs/go-ipfs/repo/config".CurrentCommit=$(commit)"
4
5 build:
4 - go build
6 + go build -ldflags=$(ldflags)
7
8 install: build
9 go install
core/commands/version.go
+15 -2
@@ -11,6 +11,7 @@ import (
11
12 type VersionOutput struct {
13 Version string
14 + Commit string
15 }
16
17 var VersionCmd = &cmds.Command{
@@ -21,24 +22,36 @@ var VersionCmd = &cmds.Command{
22
23 Options: []cmds.Option{
24 cmds.BoolOption("number", "n", "Only show the version number"),
25 + cmds.BoolOption("commit", "Show the commit hash"),
26 },
27 Run: func(req cmds.Request, res cmds.Response) {
28 res.SetOutput(&VersionOutput{
29 Version: config.CurrentVersionNumber,
30 + Commit: config.CurrentCommit,
31 })
32 },
33 Marshalers: cmds.MarshalerMap{
34 cmds.Text: func(res cmds.Response) (io.Reader, error) {
35 v := res.Output().(*VersionOutput)
36
37 + commit, found, err := res.Request().Option("commit").Bool()
38 + commitTxt := ""
39 + if err != nil {
40 + return nil, err
41 + }
42 + if found && commit {
43 + commitTxt = "-" + v.Commit
44 + }
45 +
46 number, found, err := res.Request().Option("number").Bool()
47 if err != nil {
48 return nil, err
49 }
50 if found && number {
39 - return strings.NewReader(fmt.Sprintln(v.Version)), nil
51 + return strings.NewReader(fmt.Sprintln(v.Version + commitTxt)), nil
52 }
41 - return strings.NewReader(fmt.Sprintf("ipfs version %s\n", v.Version)), nil
53 +
54 + return strings.NewReader(fmt.Sprintf("ipfs version %s%s\n", v.Version, commitTxt)), nil
55 },
56 },
57 Type: VersionOutput{},
repo/config/version.go
+2
@@ -9,6 +9,8 @@ import (
9
10 // CurrentVersionNumber is the current application's version literal
11 const CurrentVersionNumber = "0.3.8-dev"
12 +// CurrentCommit is the current git commit, this is set as a ldflag in the Makefile
13 +var CurrentCommit string
14
15 // Version regulates checking if the most recent version is run
16 type Version struct {