diff options
-rw-r--r-- | lib/git/refs.py | 9 | ||||
-rw-r--r-- | test/git/test_refs.py | 5 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/git/refs.py b/lib/git/refs.py index 0b8b2a98..ec70c72b 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -334,9 +334,15 @@ class SymbolicReference(object): return self new_abs_path = os.path.join(self.repo.git_dir, new_path) + cur_abs_path = os.path.join(self.repo.git_dir, self.path) if os.path.isfile(new_abs_path): if not force: - raise OSError("File at path %r already exists" % new_abs_path) + # if they point to the same file, its not an error + if open(new_abs_path,'rb').read() != open(cur_abs_path,'rb').read(): + raise OSError("File at path %r already exists" % new_abs_path) + # else: we could remove ourselves and use the otherone, but + # but clarity we just continue as usual + # END not force handling os.remove(new_abs_path) # END handle existing target file @@ -345,7 +351,6 @@ class SymbolicReference(object): os.makedirs(dirname) # END create directory - cur_abs_path = os.path.join(self.repo.git_dir, self.path) os.rename(cur_abs_path, new_abs_path) self.path = new_path diff --git a/test/git/test_refs.py b/test/git/test_refs.py index aee9b706..762554dc 100644 --- a/test/git/test_refs.py +++ b/test/git/test_refs.py @@ -267,7 +267,10 @@ class TestRefs(TestBase): # exists, fail unless we force ex_ref_path = far_away_head.path self.failUnlessRaises(OSError, ref.rename, ex_ref_path) - assert ref.rename(ex_ref_path, force=True).path == ex_ref_path and ref.object == orig_obj + # if it points to the same commit it works + far_away_head.commit = ref.commit + ref.rename(ex_ref_path) + assert ref.path == ex_ref_path and ref.object == orig_obj assert ref.rename(ref.path).path == ex_ref_path # rename to same name # create symbolic refs |