forked from toolshed/abra
cli
cmd
pkg
app
autocomplete
catalogue
client
config
container
context
dns
envfile
formatter
git
add.go
branch.go
clone.go
commit.go
common.go
diff.go
init.go
init_test.go
push.go
read.go
read_test.go
remote.go
integration
limit
lint
log
recipe
secret
server
service
ssh
test
upstream
web
scripts
tests
vendor
.dockerignore
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
43 lines
949 B
Go
43 lines
949 B
Go
package git
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"coopcloud.tech/abra/pkg/log"
|
|
)
|
|
|
|
// getGitDiffArgs builds the `git diff` invocation args. It removes the usage
|
|
// of a pager and ensures that colours are specified even when Git might detect
|
|
// otherwise.
|
|
func getGitDiffArgs(repoPath string) []string {
|
|
return []string{
|
|
"-C",
|
|
repoPath,
|
|
"--no-pager",
|
|
"-c",
|
|
"color.diff=always",
|
|
"diff",
|
|
}
|
|
}
|
|
|
|
// DiffUnstaged shows a `git diff`. Due to limitations in the underlying go-git
|
|
// library, this implementation requires the /usr/bin/git binary. It gracefully
|
|
// skips if it cannot find the command on the system.
|
|
func DiffUnstaged(path string) error {
|
|
if _, err := exec.LookPath("git"); err != nil {
|
|
log.Warnf("unable to locate git command, cannot output diff")
|
|
return nil
|
|
}
|
|
|
|
gitDiffArgs := getGitDiffArgs(path)
|
|
diff, err := exec.Command("git", gitDiffArgs...).Output()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
fmt.Print(string(diff))
|
|
|
|
return nil
|
|
}
|