Monorepo for Tangled tangled.org
2

Configure Feed

Select the types of activity you want to include in your feed.

knotmirror/git: sync HEAD seperately on resync

Ideally this should be done by dedicated event like `gitHeadUpdate`, but
as we have lots of self-hosted knots, doing all the work from knotmirror
would be easier than requesting users to update their knot again.

Signed-off-by: Seongmin Lee <git@boltless.me>

author
Seongmin Lee
committer
Tangled
date (May 16, 2026, 1:27 PM +0300) commit ed3b3c79 parent 811a6834 change-id pmtsnmsw
+32
+32
knotmirror/git.go
··· 91 91 } 92 92 return fmt.Errorf("running 'git fetch': %w\n%s", err, string(out)) 93 93 } 94 + 95 + // TODO(boltless): make this dedicated event instead 96 + lsRemoteCmd := exec.CommandContext(ctx, "git", "ls-remote", "--symref", url, "HEAD") 97 + out, err := lsRemoteCmd.CombinedOutput() 98 + if err != nil { 99 + if ctx.Err() != nil { 100 + return ctx.Err() 101 + } 102 + return fmt.Errorf("running 'git ls-remote --symref': %w\n%s", err, string(out)) 103 + } 104 + 105 + var headRef string 106 + for line := range strings.SplitSeq(string(out), "\n") { 107 + if !strings.HasPrefix(line, "ref: ") { 108 + continue 109 + } 110 + fields := strings.Fields(line) 111 + if len(fields) >= 2 { 112 + headRef = fields[1] 113 + break 114 + } 115 + } 116 + if headRef != "" { 117 + symrefCmd := exec.CommandContext(ctx, "git", "-C", path, "symbolic-ref", "HEAD", headRef) 118 + if out, err := symrefCmd.CombinedOutput(); err != nil { 119 + if ctx.Err() != nil { 120 + return ctx.Err() 121 + } 122 + return fmt.Errorf("running 'git symbolic-ref HEAD %s': %w\n%s", headRef, err, string(out)) 123 + } 124 + } 125 + 94 126 return nil 95 127 } 96 128