Commits

Anonymous committed 721ec52

found bug where you could overwrite a patch, fixed it and added test

Comments (0)

Files changed (3)

         """removes a patch from the attic dir"""
         os.unlink(self.join(patch))
 
+    def exists(self, patch):
+        """checks if a patch exists or not"""
+        return os.path.exists(self.join(patch))
+
     def available(self):
         '''reads all available patches from the attic dir
 
     d = date = user = None
     force = opts.get('force')
 
+    if name and s.exists(name) and name != s.applied and not force:
+        raise util.Abort(_('attempting to overwrite existing patch'))
     if name and s.applied and name != s.applied and not force:
         raise util.Abort(_('a different patch is active'))
     if not name:

tests/test-shelve2.bat

+@echo off
+
+rem setup hgattic in a temp test directory
+setlocal
+cd ..
+cd > tmpfile
+set /p atticdir= < tmpfile
+erase tmpfile
+cd tests
+mkdir test
+cd test
+call hg init
+cd .hg
+echo [extensions] >tmp
+echo hgattic=%atticdir%\attic.py >>tmp
+move tmp hgrc
+cd ..
+
+rem replace here with test content
+echo ### echo a ^> a.txt
+echo a > a.txt
+echo ### call hg addrem
+call hg addrem
+echo ### call hg shelve a
+call hg shelve a
+echo ### echo b ^> b.txt
+echo b > b.txt
+echo ### call hg addrem
+call hg addrem
+echo ### call hg shelve a (should fail)
+call hg shelve a
+echo ### call hg attic
+call hg attic
+rem end test content
+
+rem cleanup
+cd ..
+rmdir /S /Q test
+endlocal

tests/test-shelve2.out

+ ### echo a > a.txt
+### call hg addrem
+adding a.txt
+### call hg shelve a
+Patch a shelved
+### echo b > b.txt
+### call hg addrem
+adding b.txt
+### call hg shelve a (should fail)
+abort: attempting to overwrite existing patch
+### call hg attic
+a