Skip to content
  • Petr Baudis's avatar
    git stash: avoid data loss when "git stash save" kills a directory · a7365313
    Petr Baudis authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    "stash save" is about saving the local change to the working tree,
    but also about restoring the state of the last commit to the working
    tree.  When a local change is to turn a non-directory to a directory,
    in order to restore the non-directory, everything in the directory
    needs to be removed.
    
    Which is fine when running "git stash save --include-untracked",
    but without that option, untracked, newly created files in the
    directory will have to be discarded, if the state you are restoring
    to has a non-directory at the same path as the directory.
    
    Introduce a safety valve to fail the operation in such case, using
    the "ls-files --killed" which was designed for this exact purpose.
    
    The "stash save" is stopped when untracked files need to be
    discarded because their leading path ceased to be a directory, and
    the user is required to pass --force to really have the data
    removed.
    
    Signed-off-by: default avatarPetr Baudis <pasky@ucw.cz>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    a7365313