[cache][partial] Fix duplicate `origin`.
- Removes the hardcoded `origin` from the refspec path, this causes a
conflict if the cache is used beyond the initial checkout.
Bug: 34965
Change-Id: Ie6ff0329774ce7461a52b28a8675063b77da2ad4
Reviewed-on: https://fuchsia-review.googlesource.com/c/jiri/+/388734
Reviewed-by: Haowei Wu <haowei@google.com>
Commit-Queue: Nathan Mulcahey <nmulcahey@google.com>
diff --git a/gitutil/git.go b/gitutil/git.go
index aaa7fec..998dc74 100644
--- a/gitutil/git.go
+++ b/gitutil/git.go
@@ -139,20 +139,21 @@
// AddOrReplacePartialRemote adds a new partial remote with given name and path.
// If the name already exists, it replaces the named remote with new path.
func (g *Git) AddOrReplacePartialRemote(name, path string) error {
- configStr := fmt.Sprintf("remote.%s.url", name)
- if err := g.Config(configStr, path); err != nil {
+ configKey := fmt.Sprintf("remote.%s.url", name)
+ if err := g.Config(configKey, path); err != nil {
return err
}
- configStr = fmt.Sprintf("remote.%s.partialCloneFilter", name)
- if err := g.Config(configStr, "blob:none"); err != nil {
+ configKey = fmt.Sprintf("remote.%s.partialCloneFilter", name)
+ if err := g.Config(configKey, "blob:none"); err != nil {
return err
}
- configStr = fmt.Sprintf("remote.%s.promisor", name)
- if err := g.Config(configStr, "true"); err != nil {
+ configKey = fmt.Sprintf("remote.%s.promisor", name)
+ if err := g.Config(configKey, "true"); err != nil {
return err
}
- configStr = fmt.Sprintf("remote.%s.fetch", name)
- if err := g.Config(configStr, "+refs/heads/*:refs/remotes/origin/*"); err != nil {
+ configKey = fmt.Sprintf("remote.%s.fetch", name)
+ configVal := fmt.Sprintf("+refs/heads/*:refs/remotes/%s/*", name)
+ if err := g.Config(configKey, configVal); err != nil {
return err
}
return nil
@@ -161,12 +162,13 @@
// AddOrReplaceRemote adds a new remote with given name and path. If the name
// already exists, it replaces the named remote with new path.
func (g *Git) AddOrReplaceRemote(name, path string) error {
- configStr := fmt.Sprintf("remote.%s.url", name)
- if err := g.Config(configStr, path); err != nil {
+ configKey := fmt.Sprintf("remote.%s.url", name)
+ if err := g.Config(configKey, path); err != nil {
return err
}
- configStr = fmt.Sprintf("remote.%s.fetch", name)
- if err := g.Config(configStr, "+refs/heads/*:refs/remotes/origin/*"); err != nil {
+ configKey = fmt.Sprintf("remote.%s.fetch", name)
+ configVal := fmt.Sprintf("+refs/heads/*:refs/remotes/%s/*", name)
+ if err := g.Config(configKey, configVal); err != nil {
return err
}
return nil