GetCommitHash read git commit hash.
(repoDir string)
| 142 | |
| 143 | // GetCommitHash read git commit hash. |
| 144 | func GetCommitHash(repoDir string) (string, error) { |
| 145 | // Check if repo exists. |
| 146 | if _, err := os.Stat(repoDir); err != nil { |
| 147 | return "", fmt.Errorf("directory error: %w", err) |
| 148 | } |
| 149 | |
| 150 | cmd := exec.Command("git", "-C", repoDir, "rev-parse", "HEAD") |
| 151 | output, err := cmd.CombinedOutput() |
| 152 | if err != nil { |
| 153 | return "", fmt.Errorf("read git commit hash: %s", output) |
| 154 | } |
| 155 | |
| 156 | return strings.TrimSpace(string(output)), nil |
| 157 | } |
| 158 | |
| 159 | // GetDefaultBranch read git default branch. |
| 160 | func GetDefaultBranch(nameVersion, repoDir string) (string, error) { |