Lost files after git stash && git stash pop
Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.
What did you do before the bug happened? (Steps to reproduce your issue)
``` git init mkdir README touch README/README git add . git commit -m "Init project" echo "Test" > README/README mv README/README README2 rmdir README mv README2 README git stash git stash pop ```
What did you expect to happen? (Expected behavior)
I expected that after the git stash pop the README file would be back.
What happened instead? (Actual behavior)
This README with "Test" file was deleted and I lost 5 hours of work.
What's different between what you expected and what actually happened? The file doesn't exist anymore and I can't recover it.
Anything else you want to add:
This is just a reproducible example.
Please review the rest of the bug report below.
You can delete any lines you don't wish to share.
[System Info]
git version:
git version 2.39.2 (Apple Git-143)
cpu: arm64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Darwin 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64 compiler info: clang: 14.0.3 (clang-1403.0.22.14.1)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh
[Enabled Hooks]
Quoted 18 lines · Till Friebe
Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.What did you do before the bug happened? (Steps to reproduce your issue)
``` git init mkdir README touch README/README git add . git commit -m "Init project" echo "Test" > README/README mv README/README README2 rmdir README mv README2 README git stash git stash pop ```
Quoted 5 lines
What did you expect to happen? (Expected behavior)
I expected that after thegit stash popthe README file would be back.What happened instead? (Actual behavior)
This README with "Test" file was deleted and I lost 5 hours of work.
That is always sad to hear, when work is lost.
However, I personally wonder if this is a bug or not. First, Git is told to track a file called README/README Then the file is removed, without telling Git.
And a new, unkown file appers on disk (which collides with the name of the directory)
Using this sequence could have told Git, what is going on:
git mv README/README README2
rmdir README
git mv README2 README
(a temporary branch may be checked out, with the option
to merge-squash the final result)
An other alternative could be to tell git stash to care about untracked file(s):
git stash -u
git stash pop
Which will refuse to apply the stash.
A third alternative could be to keep the file inside an editor, to have the content still available.
However, it would/could be nice, if files are not simply deleted, but saved into a "lost+found" folder, or a wastebasket kind of thing.
But which files ?
Those that are untracked ?
They may be important (local config files, passwords, help scripts, ...) or not (.o files from a C compiler).
In some older discussions they had been named "precious" files. But, as far as I remember, there was no easy solution. In that sense I don't have a better answer.
Others may have.
Thanks for reporting, it make me read [1] and come to the conclusion that it is sometimes safer to checkout out a temporary branch, commit everything and clean up later, rather than relying too much on git stash
<https://stackoverflow.com/questions/835501/how-do-you-stash-an-untracked-file>
Quoted 7 lines
What's different between what you expected and what actually happened? The file doesn't exist anymore and I can't recover it.
Anything else you want to add:
This is just a reproducible example.
Quoted 19 lines · Torsten Bögershausen
Quoted 18 lines · Till Friebe
Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.What did you do before the bug happened? (Steps to reproduce your issue)
``` git init mkdir README touch README/README git add . git commit -m "Init project" echo "Test" > README/README mv README/README README2 rmdir README mv README2 README git stash git stash pop ```
Quoted 7 lines
Quoted 5 lines
What did you expect to happen? (Expected behavior)
I expected that after thegit stash popthe README file would be back.What happened instead? (Actual behavior)
This README with "Test" file was deleted and I lost 5 hours of work.That is always sad to hear, when work is lost.
Indeed it is. Thanks Till for providing an easy reproducer.
Quoted 1 line
However, I personally wonder if this is a bug or not.
I think whenever git overwrites an untracked file without the user passing some option indicating that they want to do so it is a bug. For example "git checkout" refuses to overwrite untracked files by default. Sadly this seems to be a known bug in do_push_stash() where we are using "git reset --hard" to remove the stashed changes from the working copy. This was documented in 94b7f1563a (Comment important codepaths regarding nuking untracked files/dirs, 2021-09-27). The stash implementation does a lot of necessary forking of subprocesses, in this case I think it would be better to call unpack_trees() directly with UNPACK_RESET_PROTECT_UNTRACKED.
Best Wishes
Phillip
Quoted 52 lines
First, Git is told to track a file called README/README Then the file is removed, without telling Git.
And a new, unkown file appers on disk (which collides with the name of the directory)Using this sequence could have told Git, what is going on:
git mv README/README README2
rmdir README
git mv README2 README(a temporary branch may be checked out, with the option
to merge-squash the final result)An other alternative could be to tell
git stashto care about untracked file(s):git stash -u
git stash popWhich will refuse to apply the stash.
A third alternative could be to keep the file inside an editor, to have the content still available.
However, it would/could be nice, if files are not simply deleted, but saved into a "lost+found" folder, or a wastebasket kind of thing.
But which files ?
Those that are untracked ?
They may be important (local config files, passwords, help scripts, ...) or not (.o files from a C compiler).In some older discussions they had been named "precious" files. But, as far as I remember, there was no easy solution. In that sense I don't have a better answer.
Others may have.Thanks for reporting, it make me read [1] and come to the conclusion that it is sometimes safer to checkout out a temporary branch, commit everything and clean up later, rather than relying too much on
git stash<https://stackoverflow.com/questions/835501/how-do-you-stash-an-untracked-file>
Quoted 7 lines
What's different between what you expected and what actually happened? The file doesn't exist anymore and I can't recover it.
Anything else you want to add:
This is just a reproducible example.
Quoted 26 lines · Phillip Wood
Quoted 25 lines · Torsten Bögershausen
Quoted 23 lines · Till Friebe
Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.What did you do before the bug happened? (Steps to reproduce your issue)
``` git init mkdir README touch README/README git add . git commit -m "Init project" echo "Test" > README/README mv README/README README2 rmdir README mv README2 README git stash git stash pop ```What did you expect to happen? (Expected behavior)
I expected that after thegit stash popthe README file would be back.What happened instead? (Actual behavior)
This README with "Test" file was deleted and I lost 5 hours of work.
Quoted 8 lines
Quoted 1 line
That is always sad to hear, when work is lost.
Indeed it is. Thanks Till for providing an easy reproducer.
Quoted 1 line
However, I personally wonder if this is a bug or not.
I think whenever git overwrites an untracked file without the user passing some option indicating that they want to do so it is a bug.
OK, agreed after reading the next sentence.
Quoted 8 lines
For example "git
checkout" refuses to overwrite untracked files by default. Sadly this seems to be a known bug indo_push_stash()where we are using "git reset --hard" to remove the stashed changes from the working copy. This was documented in94b7f1563a(Comment important codepaths regarding nuking untracked files/dirs, 2021-09-27). The stash implementation does a lot of necessary forking of subprocesses, in this case I think it would be better to callunpack_trees()directly withUNPACK_RESET_PROTECT_UNTRACKED.
Thanks for the fast response.
This is not an area of Git, where I have much understanding of the code. But is seems as if pop_stash() in builtin/stash.c
(and the called functions) seems to be the problem here ?
Hi Torsten
Quoted 14 lines · Torsten Bögershausen
Quoted 2 lines
I think whenever git overwrites an untracked file without the user passing some option indicating that they want to do so it is a bug.
OK, agreed after reading the next sentence.
Quoted 8 lines
For example "git
checkout" refuses to overwrite untracked files by default. Sadly this seems to be a known bug indo_push_stash()where we are using "git reset --hard" to remove the stashed changes from the working copy. This was documented in94b7f1563a(Comment important codepaths regarding nuking untracked files/dirs, 2021-09-27). The stash implementation does a lot of necessary forking of subprocesses, in this case I think it would be better to callunpack_trees()directly withUNPACK_RESET_PROTECT_UNTRACKED.
Quoted 5 lines
Thanks for the fast response.
This is not an area of Git, where I have much understanding of the code. But is seems as if
pop_stash()inbuiltin/stash.c
(and the called functions) seems to be the problem here ?
Confusingly it is creating the stash that deletes the untracked file because it recreates README/README. do_push_stash() in builtin/stash.c is the culprit I think. I had hoped the diff below would fix the problem but it does not seem to and breaks half a dozen test cases that seem to rely on removing untracked files. Unfortunately I don't really have time to dig any further at the moment.
Best Wishes
Phillip
builtin/stash.c +12 -8
@@ -29,6 +29,8 @@#include "exec-cmd.h" #include "reflog.h" #include "add-interactive.h" +#include "reset.h" +#include "submodule.h" #define INCLUDE_ALL_FILES 2
@@ -336,7 +338,7 @@ static int apply_cached(struct strbuf *out)return pipe_command (&cp, out->buf, out->len,NULL ,0 ,NULL ,0 ); } -static int reset_head (void ) +static int stash_reset_head (void ) {struct child_process cp =CHILD_PROCESS_INIT ;
@@ -569,7 +571,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, get_index_file(), 0, NULL))return error (_ ("could not save index tree" )); -reset_head (); +stash_reset_head ();discard_index (&the_index);repo_read_index (the_repository); }
@@ -1649,12 +1651,14 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q goto done; } }else { -struct child_process cp =CHILD_PROCESS_INIT ; - cp.git_cmd =1 ; -/* BUG: this nukes untracked files in the way */ -strvec_pushl (&cp.args,"reset" ,"--hard" ,"-q" , -"--no-recurse-submodules" ,NULL ); -if (run_command (&cp)) { +struct reset_head_opts opts = { + .flags =RESET_HEAD_HARD , + }; + +if (should_update_submodules ()) +BUG ("stash should not update submodules" ); + +if (reset_head (the_repository, &opts)) { ret =-1 ; goto done; }
PATCH 1/1 git stash needing mkdir deletes untracked file
In reply to Till FriebeFrom: Torsten Bögershausen <[email protected]>
The following sequence leads to loss of work:
git init
mkdir README
touch README/README
git add .
git commit -m "Init project"
echo "Test" > README/README
mv README/README README2
rmdir README
mv README2 README
git stash
git stash pop
The problem is, that git stash needs to create the directory README/ and to be able to do this, the file README needs to be removed. And this is, where the work was lost.
There are different possibilities preventing this loss of work:
a)
git stash does refuse the removel of the untracked file,
when a directory with the same name needs to be created
There is a small problem here:
In the ideal world, the stash would do nothing at all, and not do anything but complain.
The current code makes this hard to achieve
An other solution could be to do as much stash work as possible, but stop when the file/directory conflict is detected. This would create some inconsistent state.
b) Create the directory as needed, but rename the file before doing that. This would let the git stash proceed as usual and create a "new" file, which may be surprising for some worlflows.
This change goes for b), as it seems the most intuitive solution for Git users.
Introdue a new function rename_to_untracked_or_warn() and use it in create_directories() in entry.c
--- entry.c | 25 ++++++++++++++++++++++++- t/t3903-stash.sh | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-)
entry.c +24 -1
@@ -15,6 +15,28 @@#include "entry.h" #include "parallel-checkout.h" +static int rename_to_untracked_or_warn (const char *file) +{ +const size_t file_name_len =strlen (file); +const static char *dot_untracked =".untracked" ; +const size_t dot_un_len =strlen (dot_untracked); +struct strbuf sb; +int ret; + +strbuf_init (&sb, file_name_len + dot_un_len); +strbuf_add (&sb, file, file_name_len); +strbuf_add (&sb, dot_untracked, dot_un_len); + ret =rename (file, sb.buf); + +if (ret) { +int saved_errno = errno; +warning_errno (_ ("unable rename '%s' into '%s'" ), file, sb.buf); + errno = saved_errno; + } +strbuf_release (&sb); +return ret; +} +static void create_directories (const char *path,int path_len,const struct checkout *state) {
@@ -48,7 +70,8 @@ static void create_directories(const char *path, int path_len,*/ if (mkdir (buf,0777 )) {if (errno ==EEXIST && state->force && - !unlink_or_warn (buf) && !mkdir (buf,0777 )) + !rename_to_untracked_or_warn (buf) && + !mkdir (buf,0777 ))continue ;die_errno ("cannot create directory at '%s'" , buf); }
t/t3903-stash.sh +23 -0
@@ -1512,4 +1512,27 @@ test_expect_success 'restore untracked files even when we hit conflicts' ' ) ' +test_expect_success 'stash mkdir README needed - README.untracked created' ' + git init mkdir_needed_file_untracked && + ( + cd mkdir_needed_file_untracked && + mkdir README && + touch README/README && + git add . && + git commit -m "Add README/README" && + echo Version2 > README/README && + mv README/README README2 && + rmdir README && + mv README2 README && + git stash && + test_path_is_file README.untracked && + echo Version2 >expect && + test_cmp expect README.untracked && + rm expect && + git stash pop && + test_path_is_file README.untracked && + echo Version2 >expect && + test_cmp expect README.untracked + ) +' test_done
--
2.41.0.394.ge43f4fd0bd
Re: [PATCH v1 1/1] git stash needing mkdir deletes untracked file
Quoted 2 lines · On Tue, Aug 08, 2023 at 07:26:24PM +0200, [email protected] wrote:
From: Torsten Bögershausen <[email protected]>
.
... The following sequence leads to loss of work:
I just realized that this breaks other tests:t1092-sparse-checkout-compatibility.sh not ok 17 - diff with renames and conflicts t1092-sparse-checkout-compatibility.sh not ok 18 - diff with directory/file conflicts
However, comments are welcome:
Is it a good idea to create file called "filename.untracked" ?
Re: [PATCH v1 1/1] git stash needing mkdir deletes untracked file
In reply to [email protected]Quoted 13 lines · On Tue, Aug 8, 2023 at 3:15 PM <[email protected]> wrote:
The following sequence leads to loss of work:
git init
mkdir README
touch README/README
git add .
git commit -m "Init project"
echo "Test" > README/README
mv README/README README2
rmdir README
mv README2 README
git stash
git stash pop
Quoted 6 lines
The problem is, that
git stashneeds to create the directory README/ and to be able to do this, the file README needs to be removed. And this is, where the work was lost.
There are different possibilities preventing this loss of work:
a)
git stashdoes refuse the removel of the untracked file,
s/removel/removal/
Quoted 1 line
when a directory with the same name needs to be created
s/$/./
Quoted 4 lines
There is a small problem here:
In the ideal world, the stash would do nothing at all, and not do anything but complain.
The current code makes this hard to achieve
s/$/./
Quoted 1 line
An other solution could be to do as much stash work as possible,
s/An other/Another/
Quoted 6 lines
but stop when the file/directory conflict is detected. This would create some inconsistent state.
b) Create the directory as needed, but rename the file before doing that. This would let the
git stashproceed as usual and create a "new" file, which may be surprising for some worlflows.
s/worlflows/workflows/
Quoted 4 lines
This change goes for b), as it seems the most intuitive solution for Git users.
Introdue a new function
rename_to_untracked_or_warn()and use it
s/Introdue/Introduce/
Quoted 9 lines
in
create_directories()inentry.cReported-by Till Friebe <[email protected]>Signed-off-by Torsten Bögershausen <[email protected]>---
entry.c +2
-0@@ -15,6 +15,28 @@ +static int rename_to_untracked_or_warn (const char *file) +{
entry.c line 26
Quoted 10 lines
entry.c +10
-0+const size_t file_name_len =strlen (file); +const static char *dot_untracked =".untracked" ; +const size_t dot_un_len =strlen (dot_untracked); +struct strbuf sb; +int ret; + +strbuf_init (&sb, file_name_len + dot_un_len); +strbuf_add (&sb, file, file_name_len); +strbuf_add (&sb, dot_untracked, dot_un_len); + ret =rename (file, sb.buf);
This could probably all be simplified to:
char *to = xstrfmt("%s.untracked", file);
ret = rename(...);
...
free(to);If there is already a file named "foo.untracked", then this will overwrite it, thus potentially losing work, right? I wonder if it makes sense to be a bit more careful.
entry.c line 38
Quoted 8 lines
entry.c +8
-0+if (ret) { +int saved_errno = errno; +warning_errno (_ ("unable rename '%s' into '%s'" ), file, sb.buf); + errno = saved_errno; + } +strbuf_release (&sb); +return ret; +}
Do we want to give the user some warning/notification that their file, as a safety precaution, got renamed to "foo.untracked"?
t/t3903-stash.sh test_expect_success 'restore untracked files even when we hit conflicts' ' · line 1517
Quoted 8 lines
t/t3903-stash.sh +6
-0@@ -1512,4 +1512,27 @@ test_expect_success 'restore untracked files even when we hit conflicts' ' +test_expect_success 'stash mkdir README needed - README.untracked created' ' + git init mkdir_needed_file_untracked && + ( + cd mkdir_needed_file_untracked && + mkdir README && + touch README/README &&
s/touch/>/
t/t3903-stash.sh test_expect_success 'restore untracked files even when we hit conflicts' ' · line 1523
Quoted 3 lines
t/t3903-stash.sh +3
-0+ git add . && + git commit -m "Add README/README" && + echo Version2 > README/README &&
s/> R/>R/
Quoted 14 lines
t/t3903-stash.sh +14
-0+ mv README/README README2 && + rmdir README && + mv README2 README && + git stash && + test_path_is_file README.untracked && + echo Version2 >expect && + test_cmp expect README.untracked && + rm expect && + git stash pop && + test_path_is_file README.untracked && + echo Version2 >expect && + test_cmp expect README.untracked + ) +'
Re: [PATCH v1 1/1] git stash needing mkdir deletes untracked file
In reply to [email protected]Hi Torsten
Thanks for working on this. I've cc'd Junio for his unpack_trees() knowledge.
Quoted 34 lines · On 08/08/2023 18:26, [email protected] wrote:
From: Torsten Bögershausen <[email protected]>
The following sequence leads to loss of work:
git init
mkdir README
touch README/README
git add .
git commit -m "Init project"
echo "Test" > README/README
mv README/README README2
rmdir README
mv README2 README
git stash
git stash popThe problem is, that
git stashneeds to create the directory README/ and to be able to do this, the file README needs to be removed. And this is, where the work was lost.
There are different possibilities preventing this loss of work:
a)
git stashdoes refuse the removel of the untracked file,
when a directory with the same name needs to be created
There is a small problem here:
In the ideal world, the stash would do nothing at all, and not do anything but complain.
The current code makes this hard to achieve
An other solution could be to do as much stash work as possible, but stop when the file/directory conflict is detected. This would create some inconsistent state.b) Create the directory as needed, but rename the file before doing that. This would let the
git stashproceed as usual and create a "new" file, which may be surprising for some worlflows.
Quoted 5 lines
This change goes for b), as it seems the most intuitive solution for Git users.
Introdue a new function
rename_to_untracked_or_warn()and use it increate_directories()inentry.c
Although this change is framed in terms of changes to "git stash push" I think the underlying issue and this patch actually affects all users of unpack_trees(). For example if "README" is untracked then
git checkout <rev> README
will currently fail if <rev>:README is a blob but will succeed and remove the untracked file if <rev>:README is a tree.
I'm far from an expert in this area but I think we might want to understand why unpack_trees() sets state->force when it calls checkout_entry() before making any changes.
Best Wishes
Phillip
Quoted 85 lines
Reported-by Till Friebe <[email protected]>Signed-off-by Torsten Bögershausen <[email protected]>--- entry.c | 25 ++++++++++++++++++++++++- t/t3903-stash.sh | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-)entry.c +24
-1@@ -15,6 +15,28 @@#include "entry.h" #include "parallel-checkout.h" +static int rename_to_untracked_or_warn (const char *file) +{ +const size_t file_name_len =strlen (file); +const static char *dot_untracked =".untracked" ; +const size_t dot_un_len =strlen (dot_untracked); +struct strbuf sb; +int ret; + +strbuf_init (&sb, file_name_len + dot_un_len); +strbuf_add (&sb, file, file_name_len); +strbuf_add (&sb, dot_untracked, dot_un_len); + ret =rename (file, sb.buf); + +if (ret) { +int saved_errno = errno; +warning_errno (_ ("unable rename '%s' into '%s'" ), file, sb.buf); + errno = saved_errno; + } +strbuf_release (&sb); +return ret; +} +static void create_directories (const char *path,int path_len,const struct checkout *state) {@@ -48,7 +70,8 @@ static void create_directories(const char *path, int path_len,*/ if (mkdir (buf,0777 )) {if (errno ==EEXIST && state->force && - !unlink_or_warn (buf) && !mkdir (buf,0777 )) + !rename_to_untracked_or_warn (buf) && + !mkdir (buf,0777 ))continue ;die_errno ("cannot create directory at '%s'" , buf); }t/t3903-stash.sh +23
-1@@ -1512,4 +1512,27 @@ test_expect_success 'restore untracked files even when we hit conflicts' ' ) ' +test_expect_success 'stash mkdir README needed - README.untracked created' ' + git init mkdir_needed_file_untracked && + ( + cd mkdir_needed_file_untracked && + mkdir README && + touch README/README && + git add . && + git commit -m "Add README/README" && + echo Version2 > README/README && + mv README/README README2 && + rmdir README && + mv README2 README && + git stash && + test_path_is_file README.untracked && + echo Version2 >expect && + test_cmp expect README.untracked && + rm expect && + git stash pop && + test_path_is_file README.untracked && + echo Version2 >expect && + test_cmp expect README.untracked + ) +' test_done --2.41.0.394.ge43f4fd0bd
Re: [PATCH v1 1/1] git stash needing mkdir deletes untracked file
Quoted 4 lines · Phillip Wood
Hi Torsten
Thanks for working on this. I've cc'd Junio for his
unpack_trees()knowledge.
Thanks Eric for the review.
Hej Phillip,
I have been playing around with the whole thing some time. At the end I had a version, which did fiddle the information that we are doing a git stash (and not any other operation) into entry.c, and all test cases passed.
So in principle I can dig out all changes, polish them and send them out, after doing cleanups of course.
(And that could take a couple of days, or weeks ;-)
My main question is still open:
Is it a good idea, to create a "helper file" ? The naming can be discussed, we may stick the date/time into the filename to make it really unique, or so.
Reading the different reports and including own experience, I still think that a directory called ".deleted-by-user" or ".wastebin" or something in that style is a good idea.
What do others think ?
Re: [PATCH v1 1/1] git stash needing mkdir deletes untracked file
Hi Torsten
Sorry for the slow reply
Quoted 8 lines · Torsten Bögershausen
Quoted 4 lines · Phillip Wood
Hi Torsten
Thanks for working on this. I've cc'd Junio for his
unpack_trees()knowledge.Thanks Eric for the review.
Quoted 7 lines
Hej Phillip,
I have been playing around with the whole thing some time. At the end I had a version, which did fiddle the information that we are doing agit stash(and not any other operation) intoentry.c, and all test cases passed.
So in principle I can dig out all changes, polish them and send them out, after doing cleanups of course.
I don't think we should be treating "git stash" as a special case here - commands like "git checkout" should not be removing untracked files unprompted either.
Quoted 6 lines
(And that could take a couple of days, or weeks ;-)
My main question is still open:
Is it a good idea, to create a "helper file" ? The naming can be discussed, we may stick the date/time into the filename to make it really unique, or so.
I think stopping and telling the user that the file would be overwritten as we do in other cases would be better.
Quoted 3 lines
Reading the different reports and including own experience, I still think that a directory called ".deleted-by-user" or ".wastebin" or something in that style is a good idea.
I can see an argument for being able to opt-in to that for "git restore" and "git reset --hard" but that is a different problem to the one here.
Best Wishes
Phillip
Re: [PATCH v1 1/1] git stash needing mkdir deletes untracked file
Quoted 3 lines · Phillip Wood
Hi Torsten
Sorry for the slow reply
No problem.
Thanks for the response, I think that we have an agreement not to overwrite an untracked file, when a directory with the same name needs to be created.
I try to come up with a patch series -
starting with the stash operation.
Quoted 43 lines · Torsten Bögershausen
Quoted 8 lines · Phillip Wood
Quoted 4 lines
Hi Torsten
Thanks for working on this. I've cc'd Junio for his
unpack_trees()knowledge.Thanks Eric for the review.
Quoted 7 lines
Hej Phillip,
I have been playing around with the whole thing some time. At the end I had a version, which did fiddle the information that we are doing agit stash(and not any other operation) intoentry.c, and all test cases passed.
So in principle I can dig out all changes, polish them and send them out, after doing cleanups of course.I don't think we should be treating "git stash" as a special case here - commands like "git checkout" should not be removing untracked files unprompted either.
Quoted 6 lines
(And that could take a couple of days, or weeks ;-)
My main question is still open:
Is it a good idea, to create a "helper file" ? The naming can be discussed, we may stick the date/time into the filename to make it really unique, or so.I think stopping and telling the user that the file would be overwritten as we do in other cases would be better.
Quoted 3 lines
Reading the different reports and including own experience, I still think that a directory called ".deleted-by-user" or ".wastebin" or something in that style is a good idea.
I can see an argument for being able to opt-in to that for "git restore" and "git reset --hard" but that is a different problem to the one here.
Best Wishes
Phillip
Re: [PATCH v1 1/1] git stash needing mkdir deletes untracked file
In reply to Phillip WoodQuoted 3 lines · Phillip Wood
I don't think we should be treating "git stash" as a special case here
- commands like "git checkout" should not be removing untracked files unprompted either.
Yeah, I tend to agree. "git checkout branch path" should overwrite a leftover "path" in the working tree in response to such an explicit request, and that should equally apply for a request with pathspec e.g. "git checkout branch .", as the latter is also an explicit "please check out all paths out of the tree-ish of the branch".
But "git checkout branch" in a working tree with untracked "path" should not lose it if "branch" has it as a tracked file.
Quoted 2 lines
I think stopping and telling the user that the file would be overwritten as we do in other cases would be better.
Yup, that is what we have done and probably one of the design choices that made us successful.
Quoted 7 lines
Quoted 3 lines
Reading the different reports and including own experience, I still think that a directory called ".deleted-by-user" or ".wastebin" or something in that style is a good idea.
I can see an argument for being able to opt-in to that for "git restore" and "git reset --hard" but that is a different problem to the one here.
Yeah, I tend to agree. If anything, such a trash directory should be kept out-of-line, not inside the working tree. Perhaps in $HOME or somewhere, and not necessarily tied to the use of Git, as the way a file gets "deleted by user" is not necessarily limited to the use of Git.
Re: [PATCH v1 1/1] git stash needing mkdir deletes untracked file
In reply to Phillip WoodQuoted 8 lines · Phillip Wood
Although this change is framed in terms of changes to "git stash push" I think the underlying issue and this patch actually affects all users of
unpack_trees(). For example if "README" is untracked thengit checkout <rev> README
will currently fail if <rev>:README is a blob but will succeed and remove the untracked file if <rev>:README is a tree.
Very true, and with an .untracked file nobody asked Git to create, presumably? I am not sure if the updated behaviour is better than the current behaviour.
If "silent and unconditional removal" bothers us, I wonder if it is a lot better approach to error out and have the user sort out the mess, which is what we usually do when it gets tempting to "move it away with an arbitrary rename" like this patch tries to do. I dunno.
Thanks.
Re: [PATCH v1 1/1] git stash needing mkdir deletes untracked file
Quoted 5 lines · Junio C Hamano
Phillip Wood <[email protected]> writes:
If "silent and unconditional removal" bothers us, I wonder if it is a lot better approach to error out and have the user sort out the mess, which is what we usually
Yes I think that would be a better approach.
Best Wishes
Phillip
Quoted 8 lines
do when it gets tempting to "move it
away with an arbitrary rename" like this patch tries to do. I dunno.Thanks.