cmd/gomote: push local VERSION file if it exists
When the gomote push command is issued, a VERSION file is
generated and pushed to the gomote instance. This change
checks if there is a local VERSION file and uses the local
VERSION file if it exists.
Fixes golang/go#57068
Change-Id: I924b2b946d371c4204460b8e9d1cad0a3a6fddd6
Reviewed-on: https://go-review.googlesource.com/c/build/+/460775
Run-TryBot: Carlos Amedee <carlos@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/cmd/gomote/push.go b/cmd/gomote/push.go
index 79f7075..9f03054 100644
--- a/cmd/gomote/push.go
+++ b/cmd/gomote/push.go
@@ -286,7 +286,8 @@
if notHave > maxNotHavePrint {
logf("Remote doesn't have %d files (only showed %d).", notHave, maxNotHavePrint)
}
- if _, hasVersion := remote["VERSION"]; !hasVersion {
+ _, localHasVersion := local["VERSION"]
+ if _, remoteHasVersion := remote["VERSION"]; !remoteHasVersion && !localHasVersion {
logf("Remote lacks a VERSION file; sending a fake one")
toSend = append(toSend, "VERSION")
}
@@ -354,7 +355,7 @@
tw := tar.NewWriter(zw)
for _, file := range files {
// Special.
- if file == "VERSION" {
+ if file == "VERSION" && !localFileExists(filepath.Join(goroot, file)) {
// TODO(bradfitz): a dummy VERSION file's contents to make things
// happy. Notably it starts with "devel ". Do we care about it
// being accurate beyond that?
@@ -434,3 +435,8 @@
goroot = filepath.Clean(goroot)
return goroot, nil
}
+
+func localFileExists(path string) bool {
+ _, err := os.Stat(path)
+ return !os.IsNotExist(err)
+}