Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAborting a git commit in a repo with pre-commit hooks from the git tab does not yield the same result as aborting from the command line #6471
Comments
|
@lorenzwalthert Thanks! I can reproduce this with the code/steps above. I'll bump this up to triage for review as we continue development of RStudio. |
|
Thanks for the heads up @ronblum. I believe this is possibly a quick fix. |
|
@ronblum Is there any rough ETA for this fix? |
|
@lorenzwalthert, it looks like your intuition here is basically correct. Just to log some investigation here -- we have a ConsoleProcess class that handles these sub-processes, launched e.g. here: rstudio/src/cpp/session/modules/SessionGit.cpp Lines 430 to 460 in 1889a1b When a process is cancelled, we set an interrupt flag here: rstudio/src/cpp/session/SessionConsoleProcess.cpp Lines 404 to 407 in 1889a1b Which is eventually checked and read within our rstudio/src/cpp/session/SessionConsoleProcess.cpp Lines 422 to 424 in 1889a1b But having that return false actually implies terminating (as opposed to interrupting) the process: rstudio/src/cpp/core/system/PosixChildProcess.cpp Lines 1029 to 1039 in 1889a1b It seems like this could be fixed by sending a real interrupt to the process, although we'd of course need to check whether the current behavior is intentional for certain contexts. |
System details
Steps to reproduce the problem
git clone git@github.com:lorenzwalthert/rstudio-git-bug.gitremotes::install_github('lorenzwalthert/precommit')precommit::use_precommit().Describe the problem in detail
https://pre-commit.com is an increasingly popular framework for managing git hooks, there are specific R hooks too (disclosure: I am the maintainer). Upon committing, it stashes all non-staged changes to a cache. Aborting to commit with the RStudio git tab makes all changes that are not staged for commit lost (unless one is a git expert). This is not the case when aborting from the command line because pre-commit restores the stashes in this case from the cache.
Suspicion: Aborting the commit via the RStudio git tab is implemented with KILL and not with INT or similar (pre-commit/pre-commit#1362 (comment)) so pre-commit cannot do the cleanup.
This behaviour makes it very dangerous to use pre-commit with RStudio and for that reason I think it should be fixed.
Reference: pre-commit/pre-commit#1362
Describe the behavior you expected
I'd expect the stash to be restored after aborting the commit, i.e. that aborting a git commit on the command line results in the same git status as aborting from the RStudio git tab.
cc: @asottile