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

mkgitconfig
mkhomedir golden
mkhomedir

exec git init --bare $WORK/dotfiles.git

chezmoi init file://$WORK/dotfiles.git

# create a commit
chezmoi add $HOME${/}.file
chezmoi git add dot_file
chezmoi git commit -- --message 'Add dot_file'
chezmoi git push

chhome home2/user

# test that chezmoi init --apply inits and applies
mkgitconfig
chezmoi init --apply --force file://$WORK/dotfiles.git
cmp $HOME/.file golden/.file

chhome home/user

# create and push a new commit
edit $CHEZMOISOURCEDIR/dot_file
chezmoi git -- add dot_file
chezmoi git -- commit -m 'Update dot_file'
chezmoi git -- push

chhome home2/user

# test chezmoi update
chezmoi update
grep -count=1 '# edited' $HOME/.file

chhome home/user

# create and push a new commit
edit $CHEZMOISOURCEDIR/dot_file
chezmoi git -- add dot_file
chezmoi git -- commit -m 'Update dot_file'
chezmoi git -- push

chhome home2/user

# test chezmoi update --apply=false
chezmoi update --apply=false
grep -count=1 '# edited' $HOME/.file
chezmoi apply --force
grep -count=2 '# edited' $HOME/.file

# test chezmoi update --init
cp golden/.chezmoi.toml.tmpl $CHEZMOISOURCEDIR
chezmoi update --init
chezmoi execute-template '{{ .key }}'
stdout value

-- golden/.chezmoi.toml.tmpl --
[data]
    key = "value"
