mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 15:12:20 +00:00 
			
		
		
		
	Fix git stash pop with local changes
				
					
				
			When there are local changes to a file, and a git stash is popped that
contains other changes to that same file, git fails as follows:
    $ git stash pop
    error: Your local changes to the following files would be overwritten by merge:
            src/index.js
    Please commit your changes or stash them before you merge.
    Aborting
    $
This change adds a rule that corrects this problem as suggested [here]:
    $ git stash pop
    error: Your local changes to the following files would be overwritten by merge:
            src/index.js
    Please commit your changes or stash them before you merge.
    Aborting
    $ fuck
    git add . && git stash pop && git reset . [enter/↑/↓/ctrl+c]
    Auto-merging src/index.js
    On branch flow
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
            modified:   src/index.js
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
            modified:   src/index.js
    Dropped refs/stash@{0} (f94776d484c4278997ac6837a7b138b9b9cdead1)
    Unstaged changes after reset:
    M        src/index.js
    $
[here]: https://stackoverflow.com/questions/15126463/how-do-i-merge-local-modifications-with-a-git-stash-without-an-extra-commit/15126489#15126489
			
			
This commit is contained in:
		
							
								
								
									
										18
									
								
								tests/rules/test_git_stash_pop.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								tests/rules/test_git_stash_pop.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| import pytest | ||||
| from thefuck.rules.git_stash_pop import match, get_new_command | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| def stderr(): | ||||
|     return '''error: Your local changes to the following files would be overwritten by merge:''' | ||||
|  | ||||
|  | ||||
| def test_match(stderr): | ||||
|     assert match(Command('git stash pop', stderr=stderr)) | ||||
|     assert not match(Command('git stash')) | ||||
|  | ||||
|  | ||||
| def test_get_new_command(stderr): | ||||
|     assert get_new_command(Command('git stash pop', stderr=stderr)) \ | ||||
|            == "git add . && git stash pop && git reset ." | ||||
		Reference in New Issue
	
	Block a user