Skip to content

Commit 9b0b79b

Browse files
committed
Backport sha-in-user-agent from git-lfs#536 to release-0.5
1 parent 3267db1 commit 9b0b79b

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

git-lfs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ import (
77

88
func main() {
99
commands.Run()
10-
1110
lfs.LogHttpStats()
1211
}

lfs/lfs.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ import (
1111
"github.com/github/git-lfs/vendor/_nuts/github.com/rubyist/tracerx"
1212
)
1313

14-
const Version = "0.5.3"
15-
16-
//
17-
// Setup permissions for the given directories used here.
18-
//
1914
const (
15+
Version = "0.5.3"
2016
tempDirPerms = 0755
2117
localMediaDirPerms = 0755
2218
localLogDirPerms = 0755
@@ -25,6 +21,7 @@ const (
2521
var (
2622
LargeSizeThreshold = 5 * 1024 * 1024
2723
TempDir = filepath.Join(os.TempDir(), "git-lfs")
24+
GitCommit string
2825
UserAgent string
2926
LocalWorkingDir string
3027
LocalGitDir string
@@ -108,10 +105,17 @@ func init() {
108105

109106
}
110107

111-
UserAgent = fmt.Sprintf("git-lfs/%s (GitHub; %s %s; go %s)", Version,
108+
gitCommit := ""
109+
if len(GitCommit) > 0 {
110+
gitCommit = "; git " + GitCommit
111+
}
112+
UserAgent = fmt.Sprintf("git-lfs/%s (GitHub; %s %s; go %s%s)",
113+
Version,
112114
runtime.GOOS,
113115
runtime.GOARCH,
114-
strings.Replace(runtime.Version(), "go", "", 1))
116+
strings.Replace(runtime.Version(), "go", "", 1),
117+
gitCommit,
118+
)
115119
}
116120

117121
func resolveGitDir() (string, string, error) {

script/build.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ var (
2525
"windows": "Windows",
2626
"amd64": "AMD64",
2727
}
28+
LdFlag string
2829
)
2930

3031
func mainBuild() {
31-
cmd, err := exec.Command("script/fmt").Output()
32+
if *ShowHelp {
33+
fmt.Println("usage: script/bootstrap [-os] [-arch] [-all]")
34+
flag.PrintDefaults()
35+
return
36+
}
37+
38+
cmd, err := exec.Command("git", "rev-parse", "--short", "HEAD").Output()
3239
if err != nil {
3340
panic(err)
3441
}
3542

3643
if len(cmd) > 0 {
37-
fmt.Println(string(cmd))
38-
}
39-
40-
if *ShowHelp {
41-
fmt.Println("usage: script/bootstrap [-os] [-arch] [-all]")
42-
flag.PrintDefaults()
43-
return
44+
LdFlag = strings.TrimSpace("-X github.com/github/git-lfs/lfs.GitCommit " + string(cmd))
4445
}
4546

4647
buildMatrix := make(map[string]Release)
47-
4848
errored := false
4949

5050
if *BuildAll {
@@ -128,7 +128,14 @@ func buildCommand(dir, buildos, buildarch string) error {
128128
bin = bin + ".exe"
129129
}
130130

131-
cmd := exec.Command("go", "build", "-o", bin, ".")
131+
args := make([]string, 1, 6)
132+
args[0] = "build"
133+
if len(LdFlag) > 0 {
134+
args = append(args, "-ldflags", LdFlag)
135+
}
136+
args = append(args, "-o", bin, ".")
137+
138+
cmd := exec.Command("go", args...)
132139
if addenv {
133140
cmd.Env = []string{
134141
"GOOS=" + buildos,

script/run

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/sh
22
script/fmt
3-
go run ./git-lfs.go "$@"
3+
commit=`git rev-parse --short HEAD`
4+
go run -ldflags="-X github.com/github/git-lfs/lfs.GitCommit $commit" ./git-lfs.go "$@"

0 commit comments

Comments
 (0)