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 <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2023-11-30 22:07:50 -08:00
parent d82637582c
commit 6028094e6b
3 changed files with 68 additions and 3 deletions

View File

@ -52,6 +52,15 @@ func GitSetRemote(c *Git, tb testing.TB, name string, url string) {
require.NoError(tb, err)
}
func GitSetMainUpstream(c *Git, tb testing.TB, remote, target string) {
tb.Helper()
_, err := fakeGit(c, "fetch", "--depth", "1", remote, target)
require.NoError(tb, err)
_, err = fakeGit(c, "branch", "--set-upstream-to", remote+"/"+target, "main")
require.NoError(tb, err)
}
func Mktmp(tb testing.TB) string {
tb.Helper()
folder := tb.TempDir()