Skip to content

feat: add dotfiles command #1723

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 32 commits into from
May 25, 2022
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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 symlink backup test
  • Loading branch information
f0ssel committed May 25, 2022
commit b265149ff849c716bc1f14fb14b79f8aa91bcaef
36 changes: 36 additions & 0 deletions cli/dotfiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,42 @@ func TestDotfiles(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, string(b), "wow\n")
})
t.Run("SymlinkBackup", func(t *testing.T) {
_, root := clitest.New(t)
testRepo := testGitRepo(t, root)

// nolint:gosec
err := os.WriteFile(filepath.Join(testRepo, ".bashrc"), []byte("wow"), 0750)
assert.NoError(t, err)

// add a conflicting file at destination
// nolint:gosec
err = os.WriteFile(filepath.Join(string(root), ".bashrc"), []byte("backup"), 0750)
assert.NoError(t, err)

c := exec.Command("git", "add", ".bashrc")
c.Dir = testRepo
err = c.Run()
assert.NoError(t, err)

c = exec.Command("git", "commit", "-m", `"add .bashrc"`)
c.Dir = testRepo
out, err := c.CombinedOutput()
assert.NoError(t, err, string(out))

cmd, _ := clitest.New(t, "dotfiles", "--global-config", string(root), "--symlink-dir", string(root), "-y", testRepo)
err = cmd.Execute()
assert.NoError(t, err)

b, err := os.ReadFile(filepath.Join(string(root), ".bashrc"))
assert.NoError(t, err)
assert.Equal(t, string(b), "wow")

// check for backup file
b, err = os.ReadFile(filepath.Join(string(root), ".bashrc.bak"))
assert.NoError(t, err)
assert.Equal(t, string(b), "backup")
})
}

func testGitRepo(t *testing.T, root config.Root) string {
Expand Down