exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec lefthook install
exec git add -A
exec git commit -m 'initial'

# Stage first change
exec echo "line1\nlineStaged\nline3\n"
cp stdout a.txt
grep lineStaged a.txt
exec git add a.txt

# Add unstaged change on same line
exec echo "line1\nlineUnstaged\nline3\n"
cp stdout a.txt
grep lineUnstaged a.txt

# Change that line in the hook
! exec git commit -m 'test'

# Must restore the state before running the hook
grep lineUnstaged a.txt
! grep line42 a.txt
grep lineCommitted b.txt

stderr '\s*conflict while merging unstaged changes\s*'

-- lefthook.yml --
pre-commit:
  jobs:
    - run: echo "line1\nline42\nline3\n" > a.txt
    - run: echo "line1\nline42\nline3\n" > b.txt

-- a.txt --
line1
line2
line3

-- b.txt --
line1
lineCommitted
line3

