{"thread":{"id":"63217","subject":"A cross between 'git stash create' and 'git stash push --include-untracked'?","startedAt":"2025-03-30T14:37:45Z","lastAt":"2025-03-31T07:48:00Z","messageCount":2,"participants":["Alexander Shpilkin","Patrick Steinhardt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"515301","messageId":"d8f596cfac9b001350b8b5e408067bb4caa073a7.camel@gmail.com","threadId":"63217","inReplyTo":null,"subject":"A cross between 'git stash create' and 'git stash push --include-untracked'?","fromName":"Alexander Shpilkin","fromEmail":"ashpilkin@gmail.com","sentAt":"2025-03-30T14:37:42Z","receivedAt":"2025-03-30T14:37:45Z","isPatch":false,"sender":{"key":"ashpilkin@gmail.com","avatar":null},"body":"Hi,\n\nI'm trying to write a script for my use that would run before every\ninvocation of 'make' and record the working tree state at that point. \nStripping out the boring parts, it is basically just\n\n    git update-ref --create-reflog refs/build $(git stash create)\n\nbut the problem is that what I want is less like 'git stash create' and\nmore like 'git stash create --include-untracked', in case there are any\nnew and as yet untracked source files that are nevertheless picked up\nby the build system.\n\nOf course, that does not exist and, because of the syntax of 'git stash\ncreate', cannot exist.  I've looked at the code in builtin/stash.c and\nit looks like there are only two callers of do_create_stash(): one is\ncreate_stash() and hardcodes the include_untracked argument to zero,\nthe other is do_push_stash() and (assuming I try to undo its effects\nwith 'git stash pop' afterwards) will potentially destroy my working\ntree's mtimes and cause more rebuilding than necessary.  So it seems\nlike I'm stuck here.\n\nAny suggestions?\n-- \nThanks,\nAlex\n"},{"id":"515331","messageId":"Z-pIrCp6ZewWuPI0@pks.im","threadId":"63217","inReplyTo":"d8f596cfac9b001350b8b5e408067bb4caa073a7.camel@gmail.com","subject":"Re: A cross between 'git stash create' and 'git stash push --include-untracked'?","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-03-31T07:47:56Z","receivedAt":"2025-03-31T07:48:00Z","isPatch":false,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sun, Mar 30, 2025 at 05:37:42PM +0300, Alexander Shpilkin wrote:\n> Hi,\n> \n> I'm trying to write a script for my use that would run before every\n> invocation of 'make' and record the working tree state at that point. \n> Stripping out the boring parts, it is basically just\n> \n>     git update-ref --create-reflog refs/build $(git stash create)\n> \n> but the problem is that what I want is less like 'git stash create' and\n> more like 'git stash create --include-untracked', in case there are any\n> new and as yet untracked source files that are nevertheless picked up\n> by the build system.\n> \n> Of course, that does not exist and, because of the syntax of 'git stash\n> create', cannot exist.  I've looked at the code in builtin/stash.c and\n> it looks like there are only two callers of do_create_stash(): one is\n> create_stash() and hardcodes the include_untracked argument to zero,\n> the other is do_push_stash() and (assuming I try to undo its effects\n> with 'git stash pop' afterwards) will potentially destroy my working\n> tree's mtimes and cause more rebuilding than necessary.  So it seems\n> like I'm stuck here.\n\nIndeed.\n\n> Any suggestions?\n\nI guess the obvious answer here is to extend `git stash create` so that\nit knows to handle \"--include-untracked\".\n\nUnfortunately, it wouldn't be quite as simple as just wiring up the\ncommand line option and passing the flag to `do_create_stash()` because\n`save_untracked_files()` saves untracked files by modifying the\nrepository's index. Consequentially, we would still end up modifying the\nrepository, even though the checked out files would ultimately remain\nunmodified.\n\nI think we'd have to teach `save_untracked_files()` to do the changes on\nan in-memory index instead of invoking git-update-index(1). And if it\nknew to do that we could easily wire it up for `git stash create` and\nthus implement your usecase.\n\nI won't be working on this myself as I'm short on time, but I assume\nthat patches would very much be welcome.\n\nThanks!\n\nPatrick\n"}]}