Skip to content
  • Johannes Sixt's avatar
    stash: copy the index using --index-output instead of cp -p · 3ba2e865
    Johannes Sixt authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    '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 <j6t@kdbg.org>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    3ba2e865