[!exec:git] skip 'git not found in $PATH'
[solaris] skip 'go-git uses flock which is not available on solaris'
[windows] skip 'go-git does not support file:// URLs on windows'

chmod 755 golden/git
mkgitconfig
mkhomedir golden
mkhomedir

# install fake git
cp golden/git bin

! chezmoi init
chezmoi init --use-builtin-git=true
exists $CHEZMOISOURCEDIR/.git

# create a commit
rm bin/git # disable fake git
cp golden/.file $CHEZMOISOURCEDIR/dot_file
chezmoi git add dot_file
chezmoi git commit -- --message 'Add dot_file'
cp golden/git bin # restore fake git

chhome home2/user

# test chezmoi init --use-builtin-git=true
chezmoi init --use-builtin-git=true file://$WORK/home/user/.local/share/chezmoi
exists $CHEZMOISOURCEDIR/.git
cmp $CHEZMOISOURCEDIR/dot_file golden/.file

chhome home/user

# create a second commit
rm bin/git # disable fake git
cp golden/.executable $CHEZMOISOURCEDIR/executable_dot_executable
chezmoi git add executable_dot_executable
chezmoi git commit -- --message 'Add executable_dot_executable'
cp golden/git bin # restore fake git

chhome home2/user

# test chezmoi update --use-builtin-git=true
! chezmoi update
chezmoi update --use-builtin-git=true
cmp $CHEZMOISOURCEDIR/executable_dot_executable golden/.executable

chhome home/user

# test chezmoi init --branch --use-builtin-git=true
rm bin/git # disable fake git
chezmoi git checkout -- -b new-branch
edit $CHEZMOISOURCEDIR/dot_file
chezmoi git add dot_file
chezmoi git commit -- --message 'Edit .file'
chezmoi git checkout master
cp golden/git bin # restore fake git

chhome home3/user

# test chezmoi init --apply --branch=new-branch --use-builtin-git=true
chezmoi init --apply --branch=new-branch --use-builtin-git=true file://$WORK/home/user/.local/share/chezmoi
grep '# edited' $HOME/.file

-- golden/git --
#!/bin/sh

exit 1
