Backport strings.Cut
This commit is contained in:
parent
22a5d2abf8
commit
c89d8cb759
2 changed files with 16 additions and 2 deletions
|
|
@ -112,7 +112,7 @@ func (r *ResolvedRemotes) BaseRepo(io *iostreams.IOStreams) (ghrepo.Interface, e
|
|||
}
|
||||
|
||||
// determine corresponding git remote
|
||||
owner, repo, _ := strings.Cut(baseName, "/")
|
||||
owner, repo, _ := cut(baseName, "/")
|
||||
selectedRepo := ghrepo.New(owner, repo)
|
||||
resolution := "base"
|
||||
remote, _ := r.RemoteForRepo(selectedRepo)
|
||||
|
|
@ -184,3 +184,10 @@ func (r *ResolvedRemotes) RemoteForRepo(repo ghrepo.Interface) (*Remote, error)
|
|||
}
|
||||
return nil, errors.New("not found")
|
||||
}
|
||||
|
||||
func cut(s, sep string) (before, after string, found bool) {
|
||||
if i := strings.Index(s, sep); i >= 0 {
|
||||
return s[:i], s[i+len(sep):], true
|
||||
}
|
||||
return s, "", false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ func defaultRun(opts *DefaultOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
owner, repo, _ := strings.Cut(selectedName, "/")
|
||||
owner, repo, _ := cut(selectedName, "/")
|
||||
selectedRepo = ghrepo.New(owner, repo)
|
||||
}
|
||||
}
|
||||
|
|
@ -202,3 +202,10 @@ func setDefaultRepo(remote *context.Remote, resolution string) error {
|
|||
func unsetDefaultRepo(remote *context.Remote) error {
|
||||
return git.UnsetRemoteResolution(remote.Name)
|
||||
}
|
||||
|
||||
func cut(s, sep string) (before, after string, found bool) {
|
||||
if i := strings.Index(s, sep); i >= 0 {
|
||||
return s[:i], s[i+len(sep):], true
|
||||
}
|
||||
return s, "", false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue