Skip to content

Commit fa291c0

Browse files
committed
git submodule support
1 parent 3a095fb commit fa291c0

43 files changed

Lines changed: 721 additions & 386 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ Session.vim
7272
# auto-generated tag files
7373
tags
7474

75-
.vimrc
76-
7775
/.idea/
76+
77+
/bin/

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ go:
88
- "1.10"
99

1010
before_install:
11-
- $GOPATH/src/github.com/git-time-metric/gtm/script/git2go-init.sh
12-
- $GOPATH/src/github.com/git-time-metric/gtm/script/build-libgit2-${TRAVIS_OS_NAME}.sh
11+
- make git2go
1312
- go get github.com/mattn/goveralls
1413

1514
before_deploy:
1615
- go build -v --tags static -ldflags "-X main.Version=${TRAVIS_TAG}"
1716
- tar -zcf gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.tar.gz gtm
17+
- shasum -a 256 gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.tar.gz > gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.checksum.txt
1818

1919
script:
2020
- go get -d ./...
@@ -24,7 +24,9 @@ deploy:
2424
provider: releases
2525
api_key:
2626
secure: ESUJSNG50G0iQM8iRsfdwpcH/UBH0dhAn7PhqF1F1uAfR6NeQSZwGDWumgwf3G7CX5GcfFu6PbNXlUo8+q7u12TgQ1ZoQ38vBgfLJUvwuoYPSfU2TttX9RdPSJiCCtM+UQsqDY1l7vjLOsYV3OaR9GpO21ttxaSGX3+AoAgfh24SWaLiwSNK6SEyO4B4gzJcvXdt4D31vBXfFaQ33kSP+WcbYov+R1OI/MeyHbesrmFgFwzo+CX+baIHd9FFy6iR/EMpK9YKoSOa5obMx3eINuwYFYXDxz7/kWX7CtAoChySodAbKLHGO3IY1vAvrDaaSclGgSGfK/J69KurO+RvH/4NZh1KhAgUhEXk62KxYtjS/Dr2g8G8ucXQ6nGa77QWXjWSPbwjJWF4CUMPFiRramqcS6O19v61MgRcawAQ/gxkx0XLYXSDz8RlM+rrt7ZJoJ6JSSoMhS089E46nTMroqlQWGoBFKXxIBq76mn3Qh/4TyOcFp6b8Bb224aaIrR7Teg9Pv9fTkzoO85mlhQfigdJ5PAUo6LLR0njBsY4PatTATcuW94vRmtbUaOLKiH81n7fE6NTA9gHPGB7650q4SjG0TSk45yNvDFo7hdcE2Hv7HY5+1ZmJtXE6NpmxjohDYIjcPL6tYunJgsSitzr3Ewwkb8eJVt+GHVHyqRbrcg=
27-
file: gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.tar.gz
27+
file:
28+
- "gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.tar.gz"
29+
- "gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.checksum.txt"
2830
skip_cleanup: true
2931
overwrite: true
3032
on:

Makefile

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,87 @@
1-
BINARY=gtm
2-
VERSION=gtm-dev-$(shell date +'%Y.%m.%d-%H:%M:%S')
3-
4-
LDFLAGS=-ldflags "-X main.Version=${VERSION}"
1+
BINARY = bin/gtm
2+
VERSION = gtm-dev-$(shell date +'%Y.%m.%d-%H:%M:%S')
3+
COMMIT = $(shell git show -s --format='%h' HEAD)
4+
LDFLAGS = -ldflags "-X main.Version=$(VERSION)-$(COMMIT)"
5+
GIT2GO_VERSION = v27
6+
GIT2GO_PATH = $(GOPATH)/src/github.com/libgit2/git2go
7+
PKGS = $(shell go list ./... | grep -v vendor)
8+
BUILD_TAGS = static
59

610
build:
7-
go build --tags static ${LDFLAGS} -o ${BINARY}
11+
go build --tags '$(BUILD_TAGS)' $(LDFLAGS) -o $(BINARY)
812

9-
test:
10-
go test --tags static $$(go list ./... | grep -v vendor)
13+
debug: BUILD_TAGS += debug
14+
debug: build
15+
16+
profile: BUILD_TAGS += profile
17+
profile: build
1118

12-
vet:
13-
go vet $$(go list ./... | grep -v vendor)
19+
debug-profile: BUILD_TAGS += debug profile
20+
debug-profile: build
21+
22+
test:
23+
@go test $(TEST_OPTIONS) --tags '$(BUILD_TAGS)' $(PKGS) | grep --colour -E "FAIL|$$"
1424

15-
fmt:
16-
go fmt $$(go list ./... | grep -v vendor)
25+
test-verbose: TEST_OPTIONS += -v
26+
test-verbose: test
1727

18-
install-git2go:
19-
./script/git2go-init.sh
20-
./script/build-libgit2-osx.sh
28+
lint:
29+
-@$(call color_echo, 4, "\nGo Vet"); \
30+
go vet --all --tags '$(BUILD_TAGS)' $(PKGS)
31+
-@$(call color_echo, 4, "\nError Check"); \
32+
errcheck -ignoretests -tags '$(BUILD_TAGS)' $(PKGS)
33+
-@$(call color_echo, 4, "\nIneffectual Assign"); \
34+
ineffassign ./
35+
-@$(call color_echo, 4, "\nStatic Check"); \
36+
staticcheck --tests=false --tags '$(BUILD_TAGS)' $(PKGS)
37+
-@$(call color_echo, 4, "\nGo Simple"); \
38+
gosimple --tests=false --tags '$(BUILD_TAGS)' $(PKGS)
39+
-@$(call color_echo, 4, "\nUnused"); \
40+
unused --tests=false --tags '$(BUILD_TAGS)' $(PKGS)
41+
-@$(call color_echo, 4, "\nGo Format"); \
42+
go fmt $(PKGS)
43+
-@$(call color_echo, 4, "\nLicense Check"); \
44+
ag --go -L license . |grep -v vendor/
2145

2246
install:
23-
go install --tags static ${LDFLAGS}
47+
go install --tags '$(BUILD_TAGS)' $(LDFLAGS)
2448

2549
clean:
2650
go clean
51+
rm bin/*
52+
53+
git2go-install:
54+
[[ -d $(GIT2GO_PATH) ]] || git clone https://github.com/libgit2/git2go.git $(GIT2GO_PATH) && \
55+
cd ${GIT2GO_PATH} && \
56+
git pull && \
57+
git checkout -qf $(GIT2GO_VERSION) && \
58+
git submodule update --init
59+
60+
git2go: git2go-install
61+
cd $(GIT2GO_PATH)/vendor/libgit2 && \
62+
mkdir -p install/lib && \
63+
mkdir -p build && \
64+
cd build && \
65+
cmake -DTHREADSAFE=ON \
66+
-DBUILD_CLAR=OFF \
67+
-DBUILD_SHARED_LIBS=OFF \
68+
-DCMAKE_C_FLAGS=-fPIC \
69+
-DUSE_SSH=OFF \
70+
-DCURL=OFF \
71+
-DUSE_HTTPS=OFF \
72+
-DUSE_BUNDLED_ZLIB=ON \
73+
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
74+
-DCMAKE_INSTALL_PREFIX=../install \
75+
.. && \
76+
cmake --build .
77+
78+
git2go-clean:
79+
[[ -d $(GIT2GO_PATH) ]] && rm -rf $(GIT2GO_PATH)
80+
81+
define color_echo
82+
@tput setaf $1
83+
@echo $2
84+
@tput sgr0
85+
endef
2786

28-
.PHONY: test vet install clean fmt todo note
87+
.PHONY: build test vet fmt install clean git2go-install git2go-build all-tags profile debug

appveyor.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ os: Visual Studio 2015
44

55
clone_folder: c:\gopath\src\github.com\git-time-metric\gtm
66

7+
skip_branch_with_pr: true
8+
9+
environment:
10+
GOPATH: c:\gopath
11+
PROJ_DIR: /c/gopath/src/github.com/git-time-metric/gtm
12+
713
install:
8-
- echo %PATH%
9-
- echo %GOPATH%
10-
- go version
1114
- go env
15+
- go version
1216

1317
build_script:
14-
- c:\msys64\usr\bin\bash -lc "GOPATH=/c/gopath GOROOT=/c/Go/ /c/gopath/src/github.com/git-time-metric/gtm/script/git2go-init.sh"
15-
- c:\msys64\usr\bin\bash -lc "GOPATH=/c/gopath GOROOT=/c/Go/ /c/gopath/src/github.com/git-time-metric/gtm/script/appveyor-build.sh"
18+
- c:\msys64\usr\bin\bash -lc "cd ${PROJ_DIR} && make git2go-install"
19+
- c:\msys64\usr\bin\bash -lc "/c/gopath/src/github.com/git-time-metric/gtm/script/appveyor-build.sh"
1620

1721
artifacts:
1822
- path: gtm.$(appveyor_repo_tag_name).windows.tar.gz

command/clean_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 Michael Schenk. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package command
26

37
import (
@@ -13,7 +17,7 @@ func TestCleanYes(t *testing.T) {
1317
repo := util.NewTestRepo(t, false)
1418
defer repo.Remove()
1519
repo.Seed()
16-
os.Chdir(repo.PathIn(""))
20+
os.Chdir(repo.Workdir())
1721

1822
(InitCmd{Ui: new(cli.MockUi)}).Run([]string{})
1923

@@ -32,7 +36,7 @@ func TestTerminalOnly(t *testing.T) {
3236
repo := util.NewTestRepo(t, false)
3337
defer repo.Remove()
3438
repo.Seed()
35-
os.Chdir(repo.PathIn(""))
39+
os.Chdir(repo.Workdir())
3640

3741
(InitCmd{Ui: new(cli.MockUi)}).Run([]string{})
3842

command/commit_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 Michael Schenk. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package command
26

37
import (
@@ -13,7 +17,7 @@ func TestCommitDefaultOptions(t *testing.T) {
1317
repo := util.NewTestRepo(t, false)
1418
defer repo.Remove()
1519
repo.Seed()
16-
os.Chdir(repo.PathIn(""))
20+
os.Chdir(repo.Workdir())
1721

1822
(InitCmd{Ui: new(cli.MockUi)}).Run([]string{})
1923

command/init_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 Michael Schenk. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package command
26

37
import (
@@ -11,7 +15,7 @@ import (
1115

1216
func TestInitNoGitRepo(t *testing.T) {
1317
repo := util.NewTestRepo(t, false)
14-
os.Chdir(repo.PathIn(""))
18+
os.Chdir(repo.Workdir())
1519
repo.Remove()
1620

1721
ui := new(cli.MockUi)
@@ -29,7 +33,7 @@ func TestInitDefaultOptions(t *testing.T) {
2933
repo := util.NewTestRepo(t, false)
3034
defer repo.Remove()
3135
repo.Seed()
32-
os.Chdir(repo.PathIn(""))
36+
os.Chdir(repo.Workdir())
3337

3438
ui := new(cli.MockUi)
3539
c := InitCmd{Ui: ui}
@@ -58,7 +62,7 @@ func TestInitTerminalFalse(t *testing.T) {
5862
repo := util.NewTestRepo(t, false)
5963
defer repo.Remove()
6064
repo.Seed()
61-
os.Chdir(repo.PathIn(""))
65+
os.Chdir(repo.Workdir())
6266

6367
ui := new(cli.MockUi)
6468
c := InitCmd{Ui: ui}
@@ -80,7 +84,7 @@ func TestInitTags(t *testing.T) {
8084
repo := util.NewTestRepo(t, false)
8185
defer repo.Remove()
8286
repo.Seed()
83-
os.Chdir(repo.PathIn(""))
87+
os.Chdir(repo.Workdir())
8488

8589
ui := new(cli.MockUi)
8690
c := InitCmd{Ui: ui}
@@ -102,7 +106,7 @@ func TestClearTags(t *testing.T) {
102106
repo := util.NewTestRepo(t, false)
103107
defer repo.Remove()
104108
repo.Seed()
105-
os.Chdir(repo.PathIn(""))
109+
os.Chdir(repo.Workdir())
106110

107111
ui := new(cli.MockUi)
108112
c := InitCmd{Ui: ui}

command/record.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ type RecordCmd struct {
2929
}
3030

3131
func (c RecordCmd) output(s string) {
32+
var err error
3233
if c.Out != nil {
33-
fmt.Fprint(c.Out, s)
34+
_, err = fmt.Fprint(c.Out, s)
3435
} else {
35-
fmt.Fprint(os.Stdout, s)
36+
_, err = fmt.Fprint(os.Stdout, s)
37+
}
38+
if err != nil {
39+
fmt.Printf("Error printing output, %s\n", err)
3640
}
3741
}
3842

@@ -76,14 +80,18 @@ func (c RecordCmd) Run(args []string) int {
7680
return 1
7781
}
7882

79-
fileToRecord := ""
83+
var fileToRecord string
8084
if terminal {
8185
projPath, err := scm.GitRepoPath()
8286
if err != nil {
8387
// if not found, ignore error
8488
return 0
8589
}
86-
projPath, _ = scm.Workdir(projPath)
90+
projPath, err = scm.Workdir(projPath)
91+
if err != nil {
92+
// if not found, ignore error
93+
return 0
94+
}
8795
fileToRecord = filepath.Join(projPath, ".gtm", "terminal.app")
8896
} else {
8997
fileToRecord = cmdFlags.Args()[0]
@@ -104,9 +112,17 @@ func (c RecordCmd) Run(args []string) int {
104112
c.Ui.Error(err.Error())
105113
return 1
106114
}
107-
defer os.Chdir(wd)
115+
defer func() {
116+
if err := os.Chdir(wd); err != nil {
117+
fmt.Printf("Unable to change back to working directory, %s\n", err)
118+
}
119+
}()
108120

109-
os.Chdir(filepath.Dir(fileToRecord))
121+
err = os.Chdir(filepath.Dir(fileToRecord))
122+
if err != nil {
123+
c.Ui.Error(err.Error())
124+
return 1
125+
}
110126

111127
if commitNote, err = metric.Process(true); err != nil {
112128
c.Ui.Error(err.Error())

0 commit comments

Comments
 (0)