Skip to content

Aborting 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

@lorenzwalthert

Description

@lorenzwalthert

System details

RStudio Edition : Desktop
RStudio Version : 1.2.5033
OS Version      :  macOS 10.15.3
R Version       :  3.6.1

Steps to reproduce the problem

  • clone example repo with minimal example: git clone [email protected]:lorenzwalthert/rstudio-git-bug.git
  • Install the pre-commit framework with
    remotes::install_github('lorenzwalthert/precommit')
  • initiate the hooks with precommit::use_precommit().
  • edit the two R files file1 and file2 and stage one.
  • attempt to commit via the RStudio git tab, then abort immediately.
  • The file that was not staged was stashed away during the pre-commit checks (by pre-commit) and should be restored afterwards according to pre-commit. This does not happen when committing via the RStudio git tab, but it happens when committing via the console.

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

Metadata

Metadata

Labels

bugvcsVersion control such as git and svn/subversion

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions