def test_stash_unstaged(self): """Test commit_hook._stash_unstaged""" # git stash doesn't work without an initial commit :( self.cmd('git commit --allow-empty -m msg') # Write a file with a style error a = self.write_file('a', 'style error!') # Add it to the repository self.cmd('git add ' + a) # Fix the style error but don't add it self.write_file('a', 'much better :)') # Stash any unstaged changes; check the unstaged changes disappear with commit_hook._stash_unstaged(): with open(a) as f: self.assertEquals(f.read(), 'style error!') # Check the unstaged changes return with open(a) as f: self.assertEquals(f.read(), 'much better :)') # Stash changes then pretend we crashed with self.assertRaises(TestException): with commit_hook._stash_unstaged(): raise TestException # Check the unstaged changes return with open(a) as f: self.assertEquals(f.read(), 'much better :)')
def test_stash_unstaged_untracked(self): """Test commit_hook._stash_unstaged leaves untracked files alone""" # git stash doesn't work without an initial commit :( self.cmd('git commit --allow-empty -m msg') # Write a file but don't add it a = self.write_file('a', 'untracked') # Stash changes; check nothing happened with commit_hook._stash_unstaged(): with open(a) as f: self.assertEqual(f.read(), 'untracked') # Check the file is still unmodified with open(a) as f: self.assertEquals(f.read(), 'untracked')
def test_stash_unstaged_no_initial(self): """Test commit_hook._stash_unstaged handles no initial commit""" # Write a file with a style error a = self.write_file('a', 'style error!') # Add it to the repository self.cmd('git add ' + a) # Fix the style error but don't add it self.write_file('a', 'much better :)') # A warning should be printed to screen saying nothing is stashed with commit_hook._stash_unstaged(): with open(a) as f: self.assertEquals(f.read(), 'much better :)') # Check the file is still unmodified with open(a) as f: self.assertEquals(f.read(), 'much better :)')