Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 12, 2020
1 parent 9f575ad commit 1b9b564
Show file tree
Hide file tree
Showing 25 changed files with 536 additions and 139 deletions.
7 changes: 3 additions & 4 deletions v2/cmd/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"path/filepath"
"sort"
"strings"

Expand Down Expand Up @@ -97,10 +98,8 @@ func (c *Config) runManagedCmd(cmd *cobra.Command, args []string) error {
sort.Strings(targetNames)
sb := &strings.Builder{}
for _, targetName := range targetNames {
sb.WriteString(c.DestDir)
sb.WriteByte(chezmoi.PathSeparator)
sb.WriteString(targetName)
sb.WriteByte('\n')
sb.WriteString(filepath.FromSlash(filepath.Join(c.DestDir, targetName)))
sb.WriteString(eolStr)
}
return c.writeOutputString(sb.String())
}
7 changes: 4 additions & 3 deletions v2/cmd/sourcepath.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"path/filepath"
"strings"

"github.com/spf13/cobra"
Expand All @@ -25,7 +26,7 @@ func (c *Config) runSourcePathCmd(cmd *cobra.Command, args []string) error {
c.readOnly()

if len(args) == 0 {
return c.writeOutputString(c.SourceDir)
return c.writeOutputString(c.SourceDir + eolStr)
}

s, err := c.getSourceState()
Expand All @@ -43,8 +44,8 @@ func (c *Config) runSourcePathCmd(cmd *cobra.Command, args []string) error {

sb := &strings.Builder{}
for _, targetName := range targetNames {
sb.WriteString(s.Entries[targetName].Path())
sb.WriteByte('\n')
sb.WriteString(filepath.FromSlash(s.Entries[targetName].Path()))
sb.WriteString(eolStr)
}
return c.writeOutputString(sb.String())
}
2 changes: 2 additions & 0 deletions v2/cmd/util_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"syscall"
)

const eolStr = "\n"

// enableVirtualTerminalProcessingOnWindows does nothing on POSIX systems.
func enableVirtualTerminalProcessingOnWindows(w io.Writer) error {
return nil
Expand Down
2 changes: 2 additions & 0 deletions v2/cmd/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"golang.org/x/sys/windows"
)

const eolStr = "\r\n"

// enableVirtualTerminalProcessingOnWindows enables virtual terminal processing
// on Windows. See
// https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences.
Expand Down
2 changes: 2 additions & 0 deletions v2/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func TestChezmoi(t *testing.T) {
switch cond {
case "windows":
return runtime.GOOS == "windows", nil
case "v2":
return true, nil
default:
return false, fmt.Errorf("unknown condition: %s", cond)
}
Expand Down
14 changes: 14 additions & 0 deletions v2/testdata/scripts/applyremove.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[v2] stop # FIXME

exists $HOME${/}.bashrc
exists $HOME${/}.inputrc
chezmoi apply --remove
! exists $HOME${/}.bashrc
exists $HOME${/}.inputrc

-- home/user/.bashrc --
# contents of .bashrc
-- home/user/.inputrc --
# contents of .inputrc
-- home/user/.local/share/chezmoi/.chezmoiremove --
.bashrc
4 changes: 2 additions & 2 deletions v2/testdata/scripts/cat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ chezmoi cat $HOME${/}.gitconfig
cmp stdout golden/.gitconfig

chezmoi cat $HOME${/}.symlink
cmp stdout ${CHEZMOISOURCEDIR}/symlink_dot_symlink
stdout 'target'

! chezmoi cat $HOME${/}.ssh
stdout 'not a file or symlink'
Expand All @@ -26,4 +26,4 @@ stdout 'not a file or symlink'
-- home/user/.local/share/chezmoi/private_dot_ssh/config --
# contents of .ssh/config
-- home/user/.local/share/chezmoi/symlink_dot_symlink --
# contents of .symlink
target
22 changes: 22 additions & 0 deletions v2/testdata/scripts/chattr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[v2] stop # FIXME

chezmoi chattr +empty $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}/empty_dot_bashrc

chezmoi chattr +template $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}/empty_dot_bashrc.tmpl

chezmoi chattr +private $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}/private_empty_dot_bashrc.tmpl

chezmoi chattr noempty $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}/private_dot_bashrc.tmpl

chezmoi chattr -- -template $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}/private_dot_bashrc

chezmoi chattr nop $HOME${/}.bashrc
exists ${CHEZMOISOURCEDIR}/dot_bashrc

-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
2 changes: 2 additions & 0 deletions v2/testdata/scripts/diff.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[!v2] stop 'diff format changed in v2'

chmod 700 $HOME${/}.ssh

# test that chezmoi diff generates no output when the source and destination states are equal
Expand Down
115 changes: 0 additions & 115 deletions v2/testdata/scripts/dump.txt

This file was deleted.

127 changes: 127 additions & 0 deletions v2/testdata/scripts/dumpv1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
[v2] stop 'dump format changed'

chezmoi --format=json dump
cmpenv stdout golden/dump.json

chezmoi --format=json dump $HOME${/}.bashrc
cmpenv stdout golden/dump-bashrc.json

chezmoi --format=json dump $HOME${/}.ssh
cmpenv stdout golden/dump-ssh.json

chezmoi --format=json --recursive=false dump $HOME${/}.ssh
cmpenv stdout golden/dump-ssh-non-recursive.json

chezmoi --format=yaml dump
cmpenv stdout golden/dump.yaml

! chezmoi dump $HOME${/}.inputrc
stdout 'file does not exist'

-- golden/dump.json --
[
{
"type": "file",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/dot_bashrc",
"targetPath": ".bashrc",
"empty": false,
"encrypted": false,
"perm": 420,
"template": false,
"contents": "# contents of .bashrc\n"
},
{
"type": "dir",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh",
"targetPath": ".ssh",
"exact": false,
"perm": 448,
"entries": [
{
"type": "file",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh/config",
"targetPath": ".ssh/config",
"empty": false,
"encrypted": false,
"perm": 420,
"template": false,
"contents": "# contents of .ssh/config\n"
}
]
}
]
-- golden/dump-bashrc.json --
[
{
"type": "file",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/dot_bashrc",
"targetPath": ".bashrc",
"empty": false,
"encrypted": false,
"perm": 420,
"template": false,
"contents": "# contents of .bashrc\n"
}
]
-- golden/dump-ssh.json --
[
{
"type": "dir",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh",
"targetPath": ".ssh",
"exact": false,
"perm": 448,
"entries": [
{
"type": "file",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh/config",
"targetPath": ".ssh/config",
"empty": false,
"encrypted": false,
"perm": 420,
"template": false,
"contents": "# contents of .ssh/config\n"
}
]
}
]
-- golden/dump-ssh-non-recursive.json --
[
{
"type": "dir",
"sourcePath": "$WORK/home/user/.local/share/chezmoi/private_dot_ssh",
"targetPath": ".ssh",
"exact": false,
"perm": 448,
"entries": null
}
]
-- golden/dump.yaml --
- type: file
sourcePath: $WORK/home/user/.local/share/chezmoi/dot_bashrc
targetPath: .bashrc
empty: false
encrypted: false
perm: 420
template: false
contents: |
# contents of .bashrc
- type: dir
sourcePath: $WORK/home/user/.local/share/chezmoi/private_dot_ssh
targetPath: .ssh
exact: false
perm: 448
entries:
- type: file
sourcePath: $WORK/home/user/.local/share/chezmoi/private_dot_ssh/config
targetPath: .ssh/config
empty: false
encrypted: false
perm: 420
template: false
contents: |
# contents of .ssh/config
-- home/user/.local/share/chezmoi/dot_bashrc --
# contents of .bashrc
-- home/user/.local/share/chezmoi/private_dot_ssh/config --
# contents of .ssh/config
Loading

0 comments on commit 1b9b564

Please sign in to comment.