+1

Add optional warning when attempting to commit single file but other files are staged

Chris Kline 6 years ago updated 6 years ago 1

A common operation in SG is to right-click on a specific file and choose "commit". This stages (if necessary) the specific file and prepares to commit it. 


However, if other files are already staged, they will be added to the commit even if that was not the intention. This fairly frequently causes accidental commits in our codebase, because the user assumes SG is going to commit only the selected file, but ends up committing other staged files as well because they forget to double-check the pre-commit dialog.


This is particularly common when lots of files are modified, because that can result in some staged files being "offscreen" in the "Files" window at the time the user selects the individual file. 


SmartGit already has a similar warning when someone is submitting "staged modified" files (to ask if only the staged changes should be submitted, versus all changes), so there is precedent for this kind of helpful warning.


Example: In the image below I right-clicked on the highlighted .gitignore file to commit it. If I am in a rush and forget to check the pre-commit dialog, I'll accidentally commit 3 files instead of one.


Image 242

** Alternately (and perhaps ideally) SG would just disable the "submit" button when right-clicking a single file when other files are staged but not selected. This would prevent the problem entirely.

Thanks for looking into this, Marc. 


I just tried it out in the latest build (18.2 preview 6 #13110, installed: #13077) and 

  1. I don't see any difference in behavior when log.forceLocalActionsOnEntireRepository is true versus false. 
  2. I find it confusing that this option (I think?) affects both the "commit" button on the toolbar and the right-click > commit behavior. 
  3. Neither option allows you to commit a single specific staged file when other files are staged.

Here's the behavior I would like to see is that the toolbar icon ignores selection completely and operates on all files, while the right-click menu item operates solely on selected files:


Test A:

  1. Set up a repo with 3 locally modified files where none are staged
  2. Make sure no files are selected and click the "commit" button on the toolbar
    • Expected: all 3 modified files are prepared for commit
  3. Select one or more files and click the "commit" button on the toolbar
    • Expected: same as before --> all 3 modified files are prepared for commit
  4. Select a single modified file and right click > commit
    • Expected: just that single file is prepared for commit
  5. Select 2 of the modified files and right click > commit
    • Expected: only those 2 files are prepared for commit

Test B:

  1. Set up a repo with 3 locally modified files, where 2 of the 3 files are staged
  2. Make sure no files are selected and click the "commit" button on the toolbar
    • Expected: only the 2 staged files are prepared for commit
  3. Select one or more files and click the "commit" button on the toolbar
    • Expected: same as before --> only the 2 staged files are prepared for commit
  4. Select the single un-staged modified file and right click > commit
    • Expected: just that single file is prepared for commit, the other 2 staged files are ignored
  5. Select only 1 of the 2 staged files and right click > commit
    • Expected: only that single staged file is prepared for commit, the other staged file and the unstaged modified file are ignored
  6. Select both of the 2 staged files and right click > commit
    • Expected: only those two selected files are prepared for commit, the other unstaged modified file is ignored
  7. Select the un-staged modified file and 1 of the staged files and right click > commit
    • Expected: only the two selected files are prepared for commit, the other staged file is ignored