[!exec:true] skip 'true not found in $PATH'

mkhomedir

# test that chezmoi cd creates the working tree if needed
! exists $CHEZMOISOURCEDIR
chezmoi cd
exists $CHEZMOISOURCEDIR
exists $CHEZMOISOURCEDIR/home

# test that chezmoi add adds a file into the source directory
chezmoi add $HOME${/}.file
cp golden/.file $CHEZMOISOURCEDIR/home/dot_file

chhome home2/user

# test chezmoi init --working-tree creates the correct directory
chezmoi init --working-tree=$HOME${/}.dotfiles --source=$HOME${/}.dotfiles${/}home
exists $HOME/.dotfiles/.git
exists $HOME/.dotfiles/home

chhome home3/user

# test that chezmoi add returns an error if the source directory is not in the working tree
mkhomedir
! chezmoi add $HOME${/}.file
stderr 'not in'

# test that chezmoi docs does not return an error if the source directory is not in the working tree
chezmoi docs

-- golden/.file --
# contents of .file
-- home/user/.config/chezmoi/chezmoi.toml --
workingTree = "~/.local/share/chezmoi"
sourceDir = "~/.local/share/chezmoi/home"
[cd]
    command = "true"
-- home3/user/.config/chezmoi/chezmoi.toml --
workingTree = "~/.local/share/chezmoi/home"
sourceDir = "~/.local/share/chezmoi"
