On Fri, Apr 27, 2018 at 10:03 AM, Duy Nguyen <pclouds@xxxxxxxxx> wrote: > On Wed, Apr 25, 2018 at 5:18 PM, Marc Branchaud <marcnarc@xxxxxxxxxxx> wrote: >> >> * In a "file checkout" ("git checkout -- path/to/file"), $1 and $2 are >> identical so the above loop does nothing. Offhand I'm not even sure how a >> hook might get the right files in this case. > > This is a limitation of the current post-checkout hook. $3==0 from the > hook lets us know this is not a branch switch, but it does not really > tell you the affected paths. If it somehow passes all the given > pathspec to you, then you should be able to do "git ls-files -- > $pathspec" which gives you the exact same set of paths that > git-checkout updates. We could do this by setting $4 to "--" and put > all the pathspecs in $5+ [1] e.g. "HEAD@{1} HEAD 0 -- path/to/file" in > the above example. > > There is third case here, if you do "git checkout <tree-ish> -- > path/to/file" then it cannot be covered by the current design. I guess > we could set $3 to '2' (retrieve from a tree) to indicate this in > addition to 0 (from index) and 1 (from switching branch) and then $1 > could be the tree in question (pathspecs are passed the same way > above) > > [1] I wonder if we could have a more generic approach to pass > pathspecs via environment, which could work for more than just this > one hook. Not sure if it's a good idea though. Here's a crazy idea -- maybe instead of a list of pathspecs you just provide the timestamp of when git checkout started. Then the hook could walk the tree, find all files with modification times at least that late, and modify them all back to the the timestamp of when the git checkout started. Would that be enough? Is that too crazy? Sure, people could concurrently edit a file or run another program that modified files, but if you're doing that you're already playing race games with whether your next incremental build is going to be able to be correct. (Some (annoying) IDEs explicitly lock you out from editing files during a build to attempt to avoid this very problem.) That does leave one other caveat: If people intentionally do really weird stuff with having files with modification timestamps far in the future. However, it seems likely that the group of people doing that, if non-zero in number, is likely to be dis-joint with the group of folks that want this special uniform-timestamp-across-files-in-a-checkout behavior.