| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -334,9 +334,15 @@ def rename(self, new_path, force=False): | |||
| 334 | 334 | return self | |
| 335 | 335 | ||
| 336 | 336 | new_abs_path = os.path.join(self.repo.git_dir, new_path) | |
| 337 | + cur_abs_path = os.path.join(self.repo.git_dir, self.path) | ||
| 337 | 338 | if os.path.isfile(new_abs_path): | |
| 338 | 339 | if not force: | |
| 339 | - raise OSError("File at path %r already exists" % new_abs_path) | ||
| 340 | + # if they point to the same file, its not an error | ||
| 341 | + if open(new_abs_path,'rb').read() != open(cur_abs_path,'rb').read(): | ||
| 342 | + raise OSError("File at path %r already exists" % new_abs_path) | ||
| 343 | + # else: we could remove ourselves and use the otherone, but | ||
| 344 | + # but clarity we just continue as usual | ||
| 345 | + # END not force handling | ||
| 340 | 346 | os.remove(new_abs_path) | |
| 341 | 347 | # END handle existing target file | |
| 342 | 348 | ||
@@ -345,7 +351,6 @@ def rename(self, new_path, force=False): | |||
| 345 | 351 | os.makedirs(dirname) | |
| 346 | 352 | # END create directory | |
| 347 | 353 | ||
| 348 | - cur_abs_path = os.path.join(self.repo.git_dir, self.path) | ||
| 349 | 354 | os.rename(cur_abs_path, new_abs_path) | |
| 350 | 355 | self.path = new_path | |
| 351 | 356 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -267,7 +267,10 @@ def test_head_reset(self, rw_repo): | |||
| 267 | 267 | # exists, fail unless we force | |
| 268 | 268 | ex_ref_path = far_away_head.path | |
| 269 | 269 | self.failUnlessRaises(OSError, ref.rename, ex_ref_path) | |
| 270 | - assert ref.rename(ex_ref_path, force=True).path == ex_ref_path and ref.object == orig_obj | ||
| 270 | + # if it points to the same commit it works | ||
| 271 | + far_away_head.commit = ref.commit | ||
| 272 | + ref.rename(ex_ref_path) | ||
| 273 | + assert ref.path == ex_ref_path and ref.object == orig_obj | ||
| 271 | 274 | assert ref.rename(ref.path).path == ex_ref_path # rename to same name | |
| 272 | 275 | ||
| 273 | 276 | # create symbolic refs | |
| Back | FazBrowse Home | New Git URL |
0 commit comments