-
Notifications
You must be signed in to change notification settings - Fork 199
/
git.go
31 lines (26 loc) · 1.08 KB
/
git.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package utils
import (
"fmt"
"strings"
"github.com/werf/werf/test/pkg/utils/liveexec"
)
func SetGitRepoState(workTreeDir, repoDir, commitMessage string) error {
if err := liveexec.ExecCommand(".", "git", liveexec.ExecCommandOptions{}, []string{"init", workTreeDir, "--separate-git-dir", repoDir}...); err != nil {
return fmt.Errorf("unable to init git repo %s with work tree %s: %w", repoDir, workTreeDir, err)
}
if err := liveexec.ExecCommand(".", "git", liveexec.ExecCommandOptions{}, []string{"-C", workTreeDir, "add", "."}...); err != nil {
return fmt.Errorf("unable to add work tree %s files to git repo %s: %w", workTreeDir, repoDir, err)
}
if err := liveexec.ExecCommand(".", "git", liveexec.ExecCommandOptions{}, []string{"-C", workTreeDir, "commit", "-m", commitMessage}...); err != nil {
return fmt.Errorf("unable to commit work tree %s files to git repo %s: %w", workTreeDir, repoDir, err)
}
return nil
}
func GetHeadCommit(workTreeDir string) string {
out := SucceedCommandOutputString(
workTreeDir,
"git",
"rev-parse", "HEAD",
)
return strings.TrimSpace(out)
}