Skip to content

Commit 8f5e81a

Browse files
committed
Skip git pull in detached builds
1 parent 1492115 commit 8f5e81a

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

repo.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66
"os"
77
"os/exec"
8+
"strings"
89
"text/template"
910

1011
gfm "github.com/shurcooL/github_flavored_markdown"
@@ -21,11 +22,24 @@ type content struct {
2122
}
2223

2324
func updateRepo() {
24-
cmd := exec.Command("git", "pull")
25-
cmd.Stdout = os.Stdout
26-
cmd.Stderr = os.Stderr
27-
if err := cmd.Run(); err != nil {
28-
log.Fatalf("Error updating repository: %v", err)
25+
branchCmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
26+
out, err := branchCmd.Output()
27+
if err != nil {
28+
log.Printf("Skipping git pull (unable to detect branch): %v", err)
29+
return
30+
}
31+
32+
currentBranch := strings.TrimSpace(string(out))
33+
if currentBranch == "HEAD" || currentBranch == "" {
34+
log.Println("Skipping git pull: detached HEAD detected")
35+
return
36+
}
37+
38+
pullCmd := exec.Command("git", "pull", "--ff-only")
39+
pullCmd.Stdout = os.Stdout
40+
pullCmd.Stderr = os.Stderr
41+
if err := pullCmd.Run(); err != nil {
42+
log.Printf("Continuing without git pull (failed to update repository): %v", err)
2943
}
3044
}
3145

0 commit comments

Comments
 (0)