Make tryDetermineTrackingRef tests more respective of reality
Though it doesn't really matter, in practice upstream is always going to come before origin.
This commit is contained in:
parent
57ba5e5608
commit
62ecb1c84d
2 changed files with 16 additions and 14 deletions
|
|
@ -519,7 +519,9 @@ func initDefaultTitleBody(ctx CreateContext, state *shared.IssueMetadataState, u
|
|||
}
|
||||
|
||||
// tryDetermineTrackingRef is intended to try and find a remote branch on the same commit as the currently checked out
|
||||
// HEAD, i.e. the local branch.
|
||||
// HEAD, i.e. the local branch. If there are multiple branches that might match, the first remote is chosen, which in
|
||||
// practice is determined by the sorting algorithm applied much earlier in the process, roughly "upstream", "github", "origin",
|
||||
// and then everything else unstably sorted.
|
||||
func tryDetermineTrackingRef(gitClient *git.Client, remotes ghContext.Remotes, localBranchName string, headBranchConfig git.BranchConfig) (git.TrackingRef, bool) {
|
||||
// To try and determine the tracking ref for a local branch, we first construct a collection of refs
|
||||
// that might be tracking, given the current branch's config, and the list of known remotes.
|
||||
|
|
|
|||
|
|
@ -1643,17 +1643,17 @@ func Test_tryDetermineTrackingRef(t *testing.T) {
|
|||
name: "no match",
|
||||
cmdStubs: func(cs *run.CommandStubber) {
|
||||
cs.Register(`git config --get-regexp.+branch\\\.feature\\\.`, 0, "")
|
||||
cs.Register("git show-ref --verify -- HEAD refs/remotes/origin/feature refs/remotes/upstream/feature", 0, "abc HEAD\nbca refs/remotes/origin/feature")
|
||||
cs.Register("git show-ref --verify -- HEAD refs/remotes/upstream/feature refs/remotes/origin/feature", 0, "abc HEAD\nbca refs/remotes/upstream/feature")
|
||||
},
|
||||
remotes: context.Remotes{
|
||||
&context.Remote{
|
||||
Remote: &git.Remote{Name: "origin"},
|
||||
Repo: ghrepo.New("hubot", "Spoon-Knife"),
|
||||
},
|
||||
&context.Remote{
|
||||
Remote: &git.Remote{Name: "upstream"},
|
||||
Repo: ghrepo.New("octocat", "Spoon-Knife"),
|
||||
},
|
||||
&context.Remote{
|
||||
Remote: &git.Remote{Name: "origin"},
|
||||
Repo: ghrepo.New("hubot", "Spoon-Knife"),
|
||||
},
|
||||
},
|
||||
expectedTrackingRef: git.TrackingRef{},
|
||||
expectedFound: false,
|
||||
|
|
@ -1662,24 +1662,24 @@ func Test_tryDetermineTrackingRef(t *testing.T) {
|
|||
name: "match",
|
||||
cmdStubs: func(cs *run.CommandStubber) {
|
||||
cs.Register(`git config --get-regexp.+branch\\\.feature\\\.`, 0, "")
|
||||
cs.Register(`git show-ref --verify -- HEAD refs/remotes/origin/feature refs/remotes/upstream/feature$`, 0, heredoc.Doc(`
|
||||
cs.Register(`git show-ref --verify -- HEAD refs/remotes/upstream/feature refs/remotes/origin/feature$`, 0, heredoc.Doc(`
|
||||
deadbeef HEAD
|
||||
deadb00f refs/remotes/origin/feature
|
||||
deadbeef refs/remotes/upstream/feature
|
||||
deadb00f refs/remotes/upstream/feature
|
||||
deadbeef refs/remotes/origin/feature
|
||||
`))
|
||||
},
|
||||
remotes: context.Remotes{
|
||||
&context.Remote{
|
||||
Remote: &git.Remote{Name: "origin"},
|
||||
Repo: ghrepo.New("hubot", "Spoon-Knife"),
|
||||
},
|
||||
&context.Remote{
|
||||
Remote: &git.Remote{Name: "upstream"},
|
||||
Repo: ghrepo.New("octocat", "Spoon-Knife"),
|
||||
},
|
||||
&context.Remote{
|
||||
Remote: &git.Remote{Name: "origin"},
|
||||
Repo: ghrepo.New("hubot", "Spoon-Knife"),
|
||||
},
|
||||
},
|
||||
expectedTrackingRef: git.TrackingRef{
|
||||
RemoteName: "upstream",
|
||||
RemoteName: "origin",
|
||||
BranchName: "feature",
|
||||
},
|
||||
expectedFound: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue