-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gitutil: find default remote by tracking branch
Using this command resolves remote based on remote tracking branch of the curently selected branch and should be more precise in case we can't predict if user uses origin to mark upstream or their fork. Signed-off-by: Tonis Tiigi <[email protected]>
- Loading branch information
1 parent
d826375
commit 6028094
Showing
3 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,8 +106,9 @@ func TestGitDescribeTags(t *testing.T) { | |
|
||
func TestGitRemoteURL(t *testing.T) { | ||
type remote struct { | ||
name string | ||
url string | ||
name string | ||
url string | ||
tracking string | ||
} | ||
|
||
cases := []struct { | ||
|
@@ -165,6 +166,36 @@ func TestGitRemoteURL(t *testing.T) { | |
}, | ||
fail: true, | ||
}, | ||
{ | ||
name: "single tracking branch", | ||
remotes: []remote{ | ||
{ | ||
name: "foo", | ||
url: "https://github.com/tonistiigi/buildx.git", | ||
tracking: "master", | ||
}, | ||
}, | ||
expected: "https://github.com/tonistiigi/buildx.git", | ||
}, | ||
{ | ||
name: "fork tracking branch", | ||
remotes: []remote{ | ||
{ | ||
name: "origin", | ||
url: "[email protected]:crazy-max/buildx.git", | ||
}, | ||
{ | ||
name: "foobranch", | ||
url: "https://github.com/tonistiigi/buildx.git", | ||
tracking: "master", | ||
}, | ||
{ | ||
name: "crazymax", | ||
url: "[email protected]:crazy-max/buildx.git", | ||
}, | ||
}, | ||
expected: "https://github.com/tonistiigi/buildx.git", | ||
}, | ||
} | ||
for _, tt := range cases { | ||
tt := tt | ||
|
@@ -177,6 +208,9 @@ func TestGitRemoteURL(t *testing.T) { | |
GitCommit(c, t, "initial commit") | ||
for _, r := range tt.remotes { | ||
GitSetRemote(c, t, r.name, r.url) | ||
if r.tracking != "" { | ||
GitSetMainUpstream(c, t, r.name, r.tracking) | ||
} | ||
} | ||
|
||
ru, err := c.RemoteURL() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters