• Johannes Sixt's avatar
    stash: copy the index using --index-output instead of cp -p · 3ba2e865
    Johannes Sixt authored
    'git stash create' must operate with a temporary index. For this purpose,
    it used 'cp -p' to create a copy. -p is needed to preserve the timestamp
    of the index file. Now Jakob Pfender reported a certain combination of
    a Linux NFS client, OpenBSD NFS server, and cp implementation where this
    operation failed.
    Luckily, the first operation in git-stash after copying the index is to
    call 'git read-tree'. Therefore, use --index-output instead of 'cp -p'
    to write the copy of the index.
    --index-output requires that the specified file is on the same volume as
    the source index, so that the lock file can be rename()d. For this reason,
    the name of the temporary index is constructed in a way different from the
    other temporary files. The code path of 'stash -p' also needs a temporary
    index, but we do not use the new name because it does not depend on the
    same precondition as --index-output.
    Signed-off-by: default avatarJohannes Sixt <[email protected]>
    Signed-off-by: default avatarJunio C Hamano <[email protected]>
git-stash.sh 10.3 KB