Skip to content

Commit

Permalink
Merge pull request #174 from zaquestion/mr_checkout_track
Browse files Browse the repository at this point in the history
(fix) #159 by ensuring source project is used and add test
  • Loading branch information
zaquestion authored Jun 22, 2018
2 parents 8e99fa3 + 4e2aa70 commit d8bf437
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/mr_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var checkoutCmd = &cobra.Command{
// Check if remote already exists
if _, err := gitconfig.Local("remote." + mr.Author.Username + ".url"); err != nil {
// Find and create remote
mrProject, err := lab.GetProject(mr.ProjectID)
mrProject, err := lab.GetProject(mr.SourceProjectID)
if err != nil {
log.Fatal(err)
}
Expand Down
42 changes: 42 additions & 0 deletions cmd/mr_checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,48 @@ func Test_mrCheckoutCmdRun(t *testing.T) {
require.Contains(t, eLog, "54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0")
}

func Test_mrCheckoutCmd_track(t *testing.T) {
t.Parallel()
repo := copyTestRepo(t)

cmd := exec.Command("../lab_bin", "mr", "checkout", "1", "-t", "-b", "mrtest_track")
cmd.Dir = repo
b, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Fatal(err)
}
t.Log(string(b))

cmd = exec.Command("git", "branch")
cmd.Dir = repo

branch, err := cmd.CombinedOutput()
if err != nil {
t.Fatal(err)
}
require.Contains(t, string(branch), "mrtest")

cmd = exec.Command("git", "log", "-n1")
cmd.Dir = repo
log, err := cmd.CombinedOutput()
if err != nil {
t.Fatal(err)
}
eLog := string(log)
require.Contains(t, eLog, "Test file for MR test")
require.Contains(t, eLog, "54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0")

cmd = exec.Command("git", "remote", "-v")
cmd.Dir = repo
gitOut, err := cmd.CombinedOutput()
if err != nil {
t.Fatal(err)
}
remotes := string(gitOut)
require.Contains(t, remotes, "zaquestion git@gitlab.com:zaquestion/test.git")
}

func Test_mrCheckoutCmdRunWithDifferentName(t *testing.T) {
t.Parallel()
repo := copyTestRepo(t)
Expand Down

0 comments on commit d8bf437

Please sign in to comment.