MCPcopy Create free account
hub / github.com/go-git/go-git / AddAlternate

Method AddAlternate

storage/filesystem/dotgit/dotgit.go:1116–1142  ·  view source on GitHub ↗
(remote string)

Source from the content-addressed store, hash-verified

1114}
1115
1116func (d *DotGit) AddAlternate(remote string) error {
1117 altpath := d.fs.Join(objectsPath, infoPath, alternatesPath)
1118
1119 f, err := d.fs.OpenFile(altpath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0640)
1120 if err != nil {
1121 return fmt.Errorf("cannot open file: %w", err)
1122 }
1123 defer f.Close()
1124
1125 // locking in windows throws an error, based on comments
1126 // https://github.com/go-git/go-git/pull/860#issuecomment-1751823044
1127 // do not lock on windows platform.
1128 if runtime.GOOS != "windows" {
1129 if err = f.Lock(); err != nil {
1130 return fmt.Errorf("cannot lock file: %w", err)
1131 }
1132 defer f.Unlock()
1133 }
1134
1135 line := path.Join(remote, objectsPath) + "\n"
1136 _, err = io.WriteString(f, line)
1137 if err != nil {
1138 return fmt.Errorf("error writing 'alternates' file: %w", err)
1139 }
1140
1141 return nil
1142}
1143
1144// Alternates returns DotGit(s) based off paths in objects/info/alternates if
1145// available. This can be used to checks if it's a shared repository.

Callers

nothing calls this directly

Calls 3

JoinMethod · 0.80
OpenFileMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected