Skip to content

Commit 56ebe48

Browse files
committed
#898: Handle non-standard Git ref formats in branch name extraction
1 parent 63294e7 commit 56ebe48

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

recipe/dev/build/info.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ func (z *Info) Exec(c app_control.Control) error {
5858
}
5959

6060
headName := string(head.Name())
61-
if !strings.HasPrefix(headName, "refs/heads") {
62-
l.Warn("Unexpected ref format", esl.String("head", headName))
63-
return errors.New("unexpected git refs")
61+
var branch string
62+
63+
if strings.HasPrefix(headName, "refs/heads/") {
64+
branch = strings.ReplaceAll(headName, "refs/heads/", "")
65+
} else {
66+
// Handle detached HEAD or other ref formats (common in CI)
67+
l.Debug("Non-standard ref format detected, using hash-based branch name", esl.String("head", headName))
68+
branch = "detached-" + hash.String()[:8]
6469
}
6570

66-
branch := strings.ReplaceAll(headName, "refs/heads/", "")
67-
6871
xap, found := os.LookupEnv(app_definitions.EnvNameToolboxBuilderKey)
6972
if !found || len(xap) < 10 {
7073
l.Warn("Builder key not found or too short. Please set the build key for production release", esl.String("key", app_definitions.EnvNameToolboxBuilderKey), esl.Int("length", len(xap)))

0 commit comments

Comments
 (0)