git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [BUG] git-stash fails when tracked file is replaced with directory
@ 2016-10-19 15:34 Alex C. Reed, IV
  0 siblings, 0 replies; only message in thread
From: Alex C. Reed, IV @ 2016-10-19 15:34 UTC (permalink / raw)
  To: git

When a file is deleted from Git and replaced with a directory+file(s),
git-stash has two unexpected behaviors.  This is tested against
versions 2.8.1 and 2.10.1:


1) Old file is removed from index and newly-added directory+file(s)
are added to index.
In this scenario, 'git stash' fails with the message:

    error: <directory>: is a directory - add individual files instead
    fatal: Unable to process path <directory>
    Cannot save the current work tree state

The expected result would be that Git properly records the state
currently stored in index.


2) Old file is removed and new-added directory+file(s) are present
only in worktree, but not added to the index.
In this scenario, 'git stash -u' works fine, but 'git stash apply'
fails with the message:

    fatal: cannot create directory at '<directory>': File exists
    Could not restore untracked files from stash

The expected result would be that Git removes 'file' and replaces with
the untracked contents recorded in the original stash.


It is worth noting that Git does properly handle the scenario where
the stash operation of (1) is replaced with a commit to a temporary
branch, so this quirk seems to be restricted to stashes only.


I found a similar issue reported 22 April 2016 titled "possible bug of
git stash deleting uncommitted files in corner case".  The thread-view
of the message is here:

    http://marc.info/?t=146132568600002&r=1&w=2


Here's a quick-and-dirty bash script to re-create all three scenarios
(1, 2, and 'commit to branch'):

===== BEGIN stash-test.sh
#!/bin/bash

set -x
export GIT_TRACE=1

setup() {
  repo=$1

  # Prepare repo
  rm -rf $repo
  git init $repo
  cd $repo

  # Add initial file (symlink to external assets)
  ln -fs /external/dir dir
  git add dir
  git commit -m "Add symlink to /external/dir"

  # Replace symlink with local copy of assets
  rm dir
  mkdir -p dir
  touch dir/local_copy_of_dir_files
}

{
  ( setup stash-test-unstaged
    git stash -u
    git stash apply )

  ( setup stash-test-staged
    git add .
    git stash )

  ( setup stash-test-commit
    git add .
    git co -b stash-branch
    git commit -m "commit to branch instead of stash" )

} 2>&1 | tee stash-test.log
===== END stash-test.sh


Thanks,
-Alex Reed

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-10-19 15:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-19 15:34 [BUG] git-stash fails when tracked file is replaced with directory Alex C. Reed, IV

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).