Skip to content

feat: add --branch option to clone or checkout different dotfiles branch #8331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add unit test
  • Loading branch information
Emyrk committed Jul 5, 2023
commit 055689339c4048d3a8869e40ef321fc90da50065
51 changes: 51 additions & 0 deletions cli/dotfiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,52 @@ func TestDotfiles(t *testing.T) {
require.NoError(t, err)
require.Equal(t, string(b), "wow\n")
})
t.Run("InstallScriptChangeBranch", func(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {
t.Skip("install scripts on windows require sh and aren't very practical")
}
_, root := clitest.New(t)
testRepo := testGitRepo(t, root)

// We need an initial commit to start the `main` branch
c := exec.Command("git", "commit", "--allow-empty", "-m", `"initial commit"`)
c.Dir = testRepo
err := c.Run()
require.NoError(t, err)

// nolint:gosec
err = os.WriteFile(filepath.Join(testRepo, "install.sh"), []byte("#!/bin/bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0o750)
require.NoError(t, err)

c = exec.Command("git", "checkout", "-b", "other_branch")
c.Dir = testRepo
err = c.Run()
require.NoError(t, err)

c = exec.Command("git", "add", "install.sh")
c.Dir = testRepo
err = c.Run()
require.NoError(t, err)

c = exec.Command("git", "commit", "-m", `"add install.sh"`)
c.Dir = testRepo
err = c.Run()
require.NoError(t, err)

c = exec.Command("git", "checkout", "main")
c.Dir = testRepo
err = c.Run()
require.NoError(t, err)

inv, _ := clitest.New(t, "dotfiles", "--global-config", string(root), "--symlink-dir", string(root), "-y", testRepo, "-b", "other_branch")
err = inv.Run()
require.NoError(t, err)

b, err := os.ReadFile(filepath.Join(string(root), ".bashrc"))
require.NoError(t, err)
require.Equal(t, string(b), "wow\n")
})
t.Run("SymlinkBackup", func(t *testing.T) {
t.Parallel()
_, root := clitest.New(t)
Expand Down Expand Up @@ -152,5 +198,10 @@ func testGitRepo(t *testing.T, root config.Root) string {
err = c.Run()
require.NoError(t, err)

c = exec.Command("git", "checkout", "-b", "main")
c.Dir = dir
err = c.Run()
require.NoError(t, err)

return dir
}