1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/git/git.go
Carlos Alexandro Becker b02bec962e
feat: arch user repository integration (#2838)
* feat: aur PKGBUILD integration

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* feat: guess install, improve formatting

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: more deterministic

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* feat: binary releases, push, more tests

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* feat: accept key as text

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* feat: improvements

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* feat: srcinfo

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: compile

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: everything

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: lint

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* feat: renames, docs, etc

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* docs: link to docs

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: go mod tidy, title

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: srcinfo tmpl

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: missing close quote

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: templates

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: always defaults conflicts and provides

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: ssh command

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: maintainers can be a list

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: ensure -bin suffix, more tests and docs

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: this will never happen

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: whitespaces

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: goreleaser config

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
2022-01-20 14:59:39 -03:00

62 lines
1.4 KiB
Go

// Package git provides an integration with the git command
package git
import (
"bytes"
"errors"
"os/exec"
"strings"
"github.com/apex/log"
)
// IsRepo returns true if current folder is a git repository.
func IsRepo() bool {
out, err := Run("rev-parse", "--is-inside-work-tree")
return err == nil && strings.TrimSpace(out) == "true"
}
func RunWithEnv(env []string, args ...string) (string, error) {
// TODO: use exex.CommandContext here and refactor.
extraArgs := []string{
"-c", "log.showSignature=false",
}
args = append(extraArgs, args...)
/* #nosec */
cmd := exec.Command("git", args...)
stdout := bytes.Buffer{}
stderr := bytes.Buffer{}
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = append(cmd.Env, env...)
log.WithField("args", args).Debug("running git")
err := cmd.Run()
log.WithField("stdout", stdout.String()).
WithField("stderr", stderr.String()).
Debug("git result")
if err != nil {
return "", errors.New(stderr.String())
}
return stdout.String(), nil
}
// Run runs a git command and returns its output or errors.
func Run(args ...string) (string, error) {
return RunWithEnv([]string{}, args...)
}
// Clean the output.
func Clean(output string, err error) (string, error) {
output = strings.ReplaceAll(strings.Split(output, "\n")[0], "'", "")
if err != nil {
err = errors.New(strings.TrimSuffix(err.Error(), "\n"))
}
return output, err
}