commit
29630a5106
@ -136,13 +136,13 @@ func logPanic(loggedError error, recursive bool) string {
|
||||
if len(os.Args) > 0 {
|
||||
fmt.Fprintf(fmtWriter, " %s", strings.Join(os.Args[1:], " "))
|
||||
}
|
||||
fmt.Fprint(fmtWriter, "\n")
|
||||
fmt.Fprintln(fmtWriter)
|
||||
|
||||
logEnv(fmtWriter)
|
||||
fmt.Fprint(fmtWriter, "\n")
|
||||
fmt.Fprintln(fmtWriter)
|
||||
|
||||
fmtWriter.Write(ErrorBuffer.Bytes())
|
||||
fmt.Fprint(fmtWriter, "\n")
|
||||
fmt.Fprintln(fmtWriter)
|
||||
|
||||
fmt.Fprintln(fmtWriter, loggedError.Error())
|
||||
|
||||
|
@ -104,7 +104,8 @@ func simpleExec(stdin io.Reader, name string, arg ...string) (string, error) {
|
||||
output, err := cmd.Output()
|
||||
if _, ok := err.(*exec.ExitError); ok {
|
||||
return "", nil
|
||||
} else if err != nil {
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Sprintf("Error running %s %s", name, arg), err
|
||||
}
|
||||
|
||||
|
@ -260,42 +260,42 @@ func doHttpRequest(req *http.Request, creds Creds) (*http.Response, *WrappedErro
|
||||
func doApiRequestWithRedirects(req *http.Request, creds Creds, via []*http.Request) (*http.Response, *WrappedError) {
|
||||
res, wErr := doHttpRequest(req, creds)
|
||||
if wErr != nil {
|
||||
return res, wErr
|
||||
return nil, wErr
|
||||
}
|
||||
|
||||
if res.StatusCode == 307 {
|
||||
redirectedReq, redirectedCreds, err := newClientRequest(req.Method, res.Header.Get("Location"))
|
||||
if err != nil {
|
||||
return res, Errorf(err, err.Error())
|
||||
return nil, Errorf(err, err.Error())
|
||||
}
|
||||
|
||||
via = append(via, req)
|
||||
if seeker, ok := req.Body.(io.Seeker); ok {
|
||||
_, err := seeker.Seek(0, 0)
|
||||
if err != nil {
|
||||
return res, Error(err)
|
||||
}
|
||||
redirectedReq.Body = req.Body
|
||||
redirectedReq.ContentLength = req.ContentLength
|
||||
} else {
|
||||
return res, Errorf(nil, "Request body needs to be an io.Seeker to handle redirects.")
|
||||
seeker, ok := req.Body.(io.Seeker)
|
||||
if !ok {
|
||||
return nil, Errorf(nil, "Request body needs to be an io.Seeker to handle redirects.")
|
||||
}
|
||||
|
||||
if _, err := seeker.Seek(0, 0); err != nil {
|
||||
return nil, Error(err)
|
||||
}
|
||||
redirectedReq.Body = req.Body
|
||||
redirectedReq.ContentLength = req.ContentLength
|
||||
|
||||
if err = checkRedirect(redirectedReq, via); err != nil {
|
||||
return res, Errorf(err, err.Error())
|
||||
return nil, Errorf(err, err.Error())
|
||||
}
|
||||
|
||||
return doApiRequestWithRedirects(redirectedReq, redirectedCreds, via)
|
||||
}
|
||||
|
||||
return res, wErr
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func doApiRequest(req *http.Request, creds Creds) (*http.Response, *objectResource, *WrappedError) {
|
||||
via := make([]*http.Request, 0, 4)
|
||||
res, wErr := doApiRequestWithRedirects(req, creds, via)
|
||||
if wErr != nil {
|
||||
return res, nil, wErr
|
||||
return nil, nil, wErr
|
||||
}
|
||||
|
||||
obj := &objectResource{}
|
||||
@ -303,9 +303,10 @@ func doApiRequest(req *http.Request, creds Creds) (*http.Response, *objectResour
|
||||
|
||||
if wErr != nil {
|
||||
setErrorResponseContext(wErr, res)
|
||||
return nil, nil, wErr
|
||||
}
|
||||
|
||||
return res, obj, wErr
|
||||
return res, obj, nil
|
||||
}
|
||||
|
||||
func handleResponse(res *http.Response) *WrappedError {
|
||||
@ -401,26 +402,33 @@ func newApiRequest(method, oid string) (*http.Request, Creds, error) {
|
||||
}
|
||||
|
||||
req, creds, err := newClientRequest(method, u.String())
|
||||
if err == nil {
|
||||
req.Header.Set("Accept", mediaType)
|
||||
if res.Header != nil {
|
||||
for key, value := range res.Header {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("Accept", mediaType)
|
||||
if res.Header != nil {
|
||||
for key, value := range res.Header {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
}
|
||||
return req, creds, err
|
||||
|
||||
return req, creds, nil
|
||||
}
|
||||
|
||||
func newClientRequest(method, rawurl string) (*http.Request, Creds, error) {
|
||||
req, err := http.NewRequest(method, rawurl, nil)
|
||||
if err != nil {
|
||||
return req, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
creds, err := getCreds(req)
|
||||
return req, creds, err
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return req, creds, nil
|
||||
}
|
||||
|
||||
func getCreds(req *http.Request) (Creds, error) {
|
||||
@ -449,18 +457,18 @@ func getCreds(req *http.Request) (Creds, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func setErrorRequestContext(err *WrappedError, req *http.Request) {
|
||||
err.Set("Endpoint", Config.Endpoint().Url)
|
||||
err.Set("URL", fmt.Sprintf("%s %s", req.Method, req.URL.String()))
|
||||
setErrorHeaderContext(err, "Response", req.Header)
|
||||
}
|
||||
|
||||
func setErrorResponseContext(err *WrappedError, res *http.Response) {
|
||||
err.Set("Status", res.Status)
|
||||
setErrorHeaderContext(err, "Request", res.Header)
|
||||
setErrorRequestContext(err, res.Request)
|
||||
}
|
||||
|
||||
func setErrorRequestContext(err *WrappedError, req *http.Request) {
|
||||
err.Set("Endpoint", Config.Endpoint().Url)
|
||||
err.Set("URL", fmt.Sprintf("%s %s", req.Method, req.URL.String()))
|
||||
setErrorHeaderContext(err, "Response", req.Header)
|
||||
}
|
||||
|
||||
func setErrorHeaderContext(err *WrappedError, prefix string, head http.Header) {
|
||||
for key, _ := range head {
|
||||
contextKey := fmt.Sprintf("%s:%s", prefix, key)
|
||||
|
39
lfs/http.go
39
lfs/http.go
@ -24,24 +24,29 @@ func DoHTTP(c *Configuration, req *http.Request) (*http.Response, error) {
|
||||
}
|
||||
|
||||
func (c *Configuration) HttpClient() *http.Client {
|
||||
if c.httpClient == nil {
|
||||
tr := &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: 5 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).Dial,
|
||||
TLSHandshakeTimeout: 5 * time.Second,
|
||||
}
|
||||
sslVerify, _ := c.GitConfig("http.sslverify")
|
||||
if sslVerify == "false" || len(os.Getenv("GIT_SSL_NO_VERIFY")) > 0 {
|
||||
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
c.httpClient = &http.Client{
|
||||
Transport: tr,
|
||||
CheckRedirect: checkRedirect,
|
||||
}
|
||||
if c.httpClient != nil {
|
||||
return c.httpClient
|
||||
}
|
||||
|
||||
tr := &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: 5 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).Dial,
|
||||
TLSHandshakeTimeout: 5 * time.Second,
|
||||
}
|
||||
|
||||
sslVerify, _ := c.GitConfig("http.sslverify")
|
||||
if sslVerify == "false" || len(os.Getenv("GIT_SSL_NO_VERIFY")) > 0 {
|
||||
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
||||
c.httpClient = &http.Client{
|
||||
Transport: tr,
|
||||
CheckRedirect: checkRedirect,
|
||||
}
|
||||
|
||||
return c.httpClient
|
||||
}
|
||||
|
||||
|
15
lfs/lfs.go
15
lfs/lfs.go
@ -129,15 +129,16 @@ func recursiveResolveGitDir(dir string) (string, string, error) {
|
||||
}
|
||||
|
||||
gitDir := filepath.Join(dir, gitExt)
|
||||
if info, err := os.Stat(gitDir); err == nil {
|
||||
if info.IsDir() {
|
||||
return dir, gitDir, nil
|
||||
} else {
|
||||
return processDotGitFile(gitDir)
|
||||
}
|
||||
info, err := os.Stat(gitDir)
|
||||
if err != nil {
|
||||
return recursiveResolveGitDir(filepath.Dir(dir))
|
||||
}
|
||||
|
||||
return recursiveResolveGitDir(filepath.Dir(dir))
|
||||
if info.IsDir() {
|
||||
return dir, gitDir, nil
|
||||
}
|
||||
|
||||
return processDotGitFile(gitDir)
|
||||
}
|
||||
|
||||
func processDotGitFile(file string) (string, string, error) {
|
||||
|
@ -115,11 +115,11 @@ func decodeKV(data []byte) (*Pointer, error) {
|
||||
sizeStr, ok := parsed["size"]
|
||||
if !ok {
|
||||
return nil, errors.New("Invalid Oid")
|
||||
} else {
|
||||
size, err = strconv.ParseInt(sizeStr, 10, 0)
|
||||
if err != nil {
|
||||
return nil, errors.New("Invalid size: " + sizeStr)
|
||||
}
|
||||
}
|
||||
|
||||
size, err = strconv.ParseInt(sizeStr, 10, 0)
|
||||
if err != nil {
|
||||
return nil, errors.New("Invalid size: " + sizeStr)
|
||||
}
|
||||
|
||||
return NewPointer(oid, size), nil
|
||||
|
@ -35,9 +35,9 @@ func PointerSmudge(writer io.Writer, ptr *Pointer, workingfile string, cb CopyCa
|
||||
|
||||
if wErr != nil {
|
||||
return &SmudgeError{ptr.Oid, mediafile, wErr}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func downloadFile(writer io.Writer, ptr *Pointer, workingfile, mediafile string, cb CopyCallback) *WrappedError {
|
||||
|
19
lfs/setup.go
19
lfs/setup.go
@ -45,11 +45,9 @@ func InstallHooks(force bool) error {
|
||||
hookPath := filepath.Join(LocalGitDir, "hooks", "pre-push")
|
||||
if _, err := os.Stat(hookPath); err == nil && !force {
|
||||
return upgradeHookOrError(hookPath, "pre-push", prePushHook, prePushUpgrades)
|
||||
} else {
|
||||
return ioutil.WriteFile(hookPath, []byte(prePushHook+"\n"), 0755)
|
||||
}
|
||||
|
||||
return nil
|
||||
return ioutil.WriteFile(hookPath, []byte(prePushHook+"\n"), 0755)
|
||||
}
|
||||
|
||||
func upgradeHookOrError(hookPath, hookName, hook string, upgrades map[string]bool) error {
|
||||
@ -77,15 +75,16 @@ func upgradeHookOrError(hookPath, hookName, hook string, upgrades map[string]boo
|
||||
}
|
||||
|
||||
func InstallFilters() error {
|
||||
var err error
|
||||
err = setFilter("clean")
|
||||
if err == nil {
|
||||
err = setFilter("smudge")
|
||||
if err := setFilter("clean"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err == nil {
|
||||
err = requireFilters()
|
||||
if err := setFilter("smudge"); err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
if err := requireFilters(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setFilter(filterName string) error {
|
||||
|
@ -80,9 +80,9 @@ func CopyCallbackFile(event, filename string, index, totalFiles int) (CopyCallba
|
||||
}
|
||||
|
||||
func wrapProgressError(err error, event, filename string) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error writing Git LFS %s progress to %s: %s", event, filename, err.Error())
|
||||
}
|
||||
|
||||
return fmt.Errorf("Error writing Git LFS %s progress to %s: %s", event, filename, err.Error())
|
||||
return nil
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/github/git-lfs/lfs"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -61,27 +62,23 @@ func mainBuild() {
|
||||
if !errored {
|
||||
by, err := json.Marshal(buildMatrix)
|
||||
if err != nil {
|
||||
fmt.Println("Error encoding build matrix to json:", err)
|
||||
os.Exit(1)
|
||||
log.Fatalln("Error encoding build matrix to json:", err)
|
||||
}
|
||||
|
||||
file, err := os.Create("bin/releases/build_matrix.json")
|
||||
if err != nil {
|
||||
fmt.Println("Error creating build_matrix.json:", err)
|
||||
os.Exit(1)
|
||||
log.Fatalln("Error creating build_matrix.json:", err)
|
||||
}
|
||||
|
||||
written, err := file.Write(by)
|
||||
file.Close()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error writing build_matrix.json", err)
|
||||
os.Exit(1)
|
||||
log.Fatalln("Error writing build_matrix.json", err)
|
||||
}
|
||||
|
||||
if jsonSize := len(by); written != jsonSize {
|
||||
fmt.Printf("Expected to write %d bytes, actually wrote %d.\n", jsonSize, written)
|
||||
os.Exit(1)
|
||||
log.Fatalf("Expected to write %d bytes, actually wrote %d.\n", jsonSize, written)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -109,13 +106,13 @@ func build(buildos, buildarch string, buildMatrix map[string]Release) error {
|
||||
if addenv {
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
fmt.Println("Error setting up installer:\n", err.Error())
|
||||
log.Println("Error setting up installer:\n", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
err = setupInstaller(buildos, buildarch, dir, buildMatrix)
|
||||
if err != nil {
|
||||
fmt.Println("Error setting up installer:\n", err.Error())
|
||||
log.Println("Error setting up installer:\n", err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -17,24 +18,21 @@ var (
|
||||
|
||||
func mainRelease() {
|
||||
if *ReleaseId < 1 {
|
||||
fmt.Println("Need a valid github/git-lfs release id.")
|
||||
fmt.Println("usage: script/release -id")
|
||||
os.Exit(1)
|
||||
log.Println("Need a valid github/git-lfs release id.")
|
||||
log.Fatalln("usage: script/release -id")
|
||||
}
|
||||
|
||||
file, err := os.Open("bin/releases/build_matrix.json")
|
||||
if err != nil {
|
||||
fmt.Println("Error opening build_matrix.json:", err)
|
||||
fmt.Println("Ensure `script/bootstrap -all` has completed successfully")
|
||||
os.Exit(1)
|
||||
log.Println("Error opening build_matrix.json:", err)
|
||||
log.Fatalln("Ensure `script/bootstrap -all` has completed successfully")
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
buildMatrix := make(map[string]Release)
|
||||
if err := json.NewDecoder(file).Decode(&buildMatrix); err != nil {
|
||||
fmt.Println("Error reading build_matrix.json:", err)
|
||||
os.Exit(1)
|
||||
log.Fatalln("Error reading build_matrix.json:", err)
|
||||
}
|
||||
|
||||
for _, rel := range buildMatrix {
|
||||
@ -62,8 +60,7 @@ func release(rel Release) {
|
||||
|
||||
by, err := cmd.Output()
|
||||
if err != nil {
|
||||
fmt.Println("Error running curl:", err)
|
||||
os.Exit(1)
|
||||
log.Fatalln("Error running curl:", err)
|
||||
}
|
||||
|
||||
fmt.Println(string(by))
|
||||
|
@ -2,8 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Release struct {
|
||||
@ -21,7 +20,6 @@ func main() {
|
||||
case "release":
|
||||
mainRelease()
|
||||
default:
|
||||
fmt.Println("Unknown command:", *SubCommand)
|
||||
os.Exit(1)
|
||||
log.Fatalln("Unknown command:", *SubCommand)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user