| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -187,7 +187,7 @@ def _set_reference(self, ref): | |||
| 187 | 187 | if not os.path.isdir(directory): | |
| 188 | 188 | os.makedirs(directory) | |
| 189 | 189 | ||
| 190 | - fp = open(path, "w") | ||
| 190 | + fp = open(path, "wb") | ||
| 191 | 191 | try: | |
| 192 | 192 | fp.write(write_value) | |
| 193 | 193 | finally: | |
@@ -270,16 +270,24 @@ def _create(cls, repo, path, resolve, reference, force): | |||
| 270 | 270 | corresponding object and a detached symbolic reference will be created | |
| 271 | 271 | instead""" | |
| 272 | 272 | full_ref_path = cls._to_full_path(repo, path) | |
| 273 | - | ||
| 274 | 273 | abs_ref_path = os.path.join(repo.git_dir, full_ref_path) | |
| 275 | - if not force and os.path.isfile(abs_ref_path): | ||
| 276 | - raise OSError("Reference at %s does already exist" % full_ref_path) | ||
| 277 | 274 | ||
| 278 | - ref = cls(repo, full_ref_path) | ||
| 275 | + # figure out target data | ||
| 279 | 276 | target = reference | |
| 280 | 277 | if resolve: | |
| 281 | 278 | target = Object.new(repo, reference) | |
| 279 | + | ||
| 280 | + if not force and os.path.isfile(abs_ref_path): | ||
| 281 | + target_data = str(target) | ||
| 282 | + if isinstance(target, SymbolicReference): | ||
| 283 | + target_data = target.path | ||
| 284 | + if not resolve: | ||
| 285 | + target_data = "ref: " + target_data | ||
| 286 | + if open(abs_ref_path, 'rb').read().strip() != target_data: | ||
| 287 | + raise OSError("Reference at %s does already exist" % full_ref_path) | ||
| 288 | + # END no force handling | ||
| 282 | 289 | ||
| 290 | + ref = cls(repo, full_ref_path) | ||
| 283 | 291 | ref.reference = target | |
| 284 | 292 | return ref | |
| 285 | 293 | ||
@@ -305,6 +313,9 @@ def create(cls, repo, path, reference='HEAD', force=False ): | |||
| 305 | 313 | Returns | |
| 306 | 314 | Newly created symbolic Reference | |
| 307 | 315 | ||
| 316 | + Raises OSError | ||
| 317 | + If a (Symbolic)Reference with the same name but different contents | ||
| 318 | + already exists. | ||
| 308 | 319 | Note | |
| 309 | 320 | This does not alter the current HEAD, index or Working Tree | |
| 310 | 321 | """ | |
@@ -327,7 +338,7 @@ def rename(self, new_path, force=False): | |||
| 327 | 338 | self | |
| 328 | 339 | ||
| 329 | 340 | Raises OSError: | |
| 330 | - In case a file at path with that name already exists | ||
| 341 | + In case a file at path but a different contents already exists | ||
| 331 | 342 | """ | |
| 332 | 343 | new_path = self._to_full_path(self.repo, new_path) | |
| 333 | 344 | if self.path == new_path: | |
@@ -338,7 +349,7 @@ def rename(self, new_path, force=False): | |||
| 338 | 349 | if os.path.isfile(new_abs_path): | |
| 339 | 350 | if not force: | |
| 340 | 351 | # 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(): | ||
| 352 | + if open(new_abs_path,'rb').read().strip() != open(cur_abs_path,'rb').read().strip(): | ||
| 342 | 353 | raise OSError("File at path %r already exists" % new_abs_path) | |
| 343 | 354 | # else: we could remove ourselves and use the otherone, but | |
| 344 | 355 | # but clarity we just continue as usual | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,7 +242,9 @@ def test_head_reset(self, rw_repo): | |||
| 242 | 242 | assert ref.path == full_ref | |
| 243 | 243 | assert ref.object == rw_repo.head.commit | |
| 244 | 244 | ||
| 245 | - self.failUnlessRaises(OSError, Reference.create, rw_repo, full_ref) | ||
| 245 | + self.failUnlessRaises(OSError, Reference.create, rw_repo, full_ref, 'HEAD~20') | ||
| 246 | + # it works if it is at the same spot though and points to the same reference | ||
| 247 | + assert Reference.create(rw_repo, full_ref, 'HEAD').path == full_ref | ||
| 246 | 248 | Reference.delete(rw_repo, full_ref) | |
| 247 | 249 | ||
| 248 | 250 | # recreate the reference using a full_ref | |
@@ -279,7 +281,9 @@ def test_head_reset(self, rw_repo): | |||
| 279 | 281 | assert symref.path == symref_path | |
| 280 | 282 | assert symref.reference == cur_head.reference | |
| 281 | 283 | ||
| 282 | - self.failUnlessRaises(OSError, SymbolicReference.create, rw_repo, symref_path, cur_head.reference) | ||
| 284 | + self.failUnlessRaises(OSError, SymbolicReference.create, rw_repo, symref_path, cur_head.reference.commit) | ||
| 285 | + # it works if the new ref points to the same reference | ||
| 286 | + SymbolicReference.create(rw_repo, symref.path, symref.reference).path == symref.path | ||
| 283 | 287 | SymbolicReference.delete(rw_repo, symref) | |
| 284 | 288 | # would raise if the symref wouldn't have been deletedpbl | |
| 285 | 289 | symref = SymbolicReference.create(rw_repo, symref_path, cur_head.reference) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments