summaryrefslogtreecommitdiff
path: root/lib/git/refs.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-12-03 22:40:25 +0100
committerSebastian Thiel <byronimo@gmail.com>2009-12-03 22:40:25 +0100
commit4e729429631c84c3bd5602edcab3e7c2ab1dcce0 (patch)
tree5adf9421a59f1f136d4b0a8b7450a56692ce7936 /lib/git/refs.py
parent12276fedec49c855401262f0929f088ebf33d2cf (diff)
downloadgitpython-4e729429631c84c3bd5602edcab3e7c2ab1dcce0.tar.gz
refs.rename: improved handling as it will only raise ( if not forced ) if the destination contains different data. If it contains the same, the move will work as we can do what the user intended
Diffstat (limited to 'lib/git/refs.py')
-rw-r--r--lib/git/refs.py9
1 files changed, 7 insertions, 2 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