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

mkgitconfig
expandenv $WORK/home/user/.local/share/chezmoi/.chezmoiexternal.toml

# create a git repo
cd $WORK/repo
exec git init
exec git add .
exec git commit --message 'initial commit'
cd $WORK

# test that chezmoi apply clones the git repo
chezmoi apply
cmp $HOME/.dir/.file golden/.file

chhome home2/user
mkgitconfig
expandenv $WORK/home2/user/.local/share/chezmoi/.chezmoiexternal.toml

# test that chezmoi apply clones the git repo
chezmoi apply
cmp $HOME/.dir/.file golden/.file

# update the git repo
cd $WORK/repo
edit $WORK/repo/.file
exec git commit --message 'edit .file' .
cd $WORK

chhome home/user

# test that chezmoi apply does not pull from the git repo when refreshDuration is zero
chezmoi apply
! grep '# edited' $HOME/.dir/.file

# test that chezmoi apply --refresh-externals does pull from the git repo
chezmoi apply --refresh-externals
grep '# edited' $HOME/.dir/.file

chhome home2/user

# test that chezmoi apply does not pull from the git repo within the refresh period
chezmoi apply
! grep '# edited' $HOME/.dir/.file

# test that chezmoi dump prints the git command
chezmoi dump --format=yaml
stdout 'type: command'

-- golden/.file --
# contents of .file
-- home/user/.local/share/chezmoi/.chezmoiexternal.toml --
[".dir"]
    type = "git-repo"
    url = "file://$WORK/repo"
-- home2/user/.local/share/chezmoi/.chezmoiexternal.toml --
[".dir"]
    type = "git-repo"
    url = "file://$WORK/repo"
    refreshPeriod = "1h"
-- repo/.file --
# contents of .file
