Skip to content

Commit d40320b

Browse files
authored
Merge pull request #1675 from EliahKagan/rollback
Fix rollback bug in SymbolicReference.set_reference
2 parents d1c1f31 + e480985 commit d40320b

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

git/config.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,14 @@ def release(self) -> None:
406406
return
407407

408408
try:
409-
try:
410-
self.write()
411-
except IOError:
412-
log.error("Exception during destruction of GitConfigParser", exc_info=True)
413-
except ReferenceError:
414-
# This happens in PY3 ... and usually means that some state cannot be written
415-
# as the sections dict cannot be iterated
416-
# Usually when shutting down the interpreter, don'y know how to fix this
417-
pass
409+
self.write()
410+
except IOError:
411+
log.error("Exception during destruction of GitConfigParser", exc_info=True)
412+
except ReferenceError:
413+
# This happens in PY3 ... and usually means that some state cannot be
414+
# written as the sections dict cannot be iterated
415+
# Usually when shutting down the interpreter, don't know how to fix this
416+
pass
418417
finally:
419418
if self._lock is not None:
420419
self._lock._release_lock()

git/index/base.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,11 @@ def write(
224224
lfd = LockedFD(file_path or self._file_path)
225225
stream = lfd.open(write=True, stream=True)
226226

227-
ok = False
228227
try:
229228
self._serialize(stream, ignore_extension_data)
230-
ok = True
231-
finally:
232-
if not ok:
233-
lfd.rollback()
229+
except BaseException:
230+
lfd.rollback()
231+
raise
234232

235233
lfd.commit()
236234

git/refs/log.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ def to_file(self, filepath: PathLike) -> None:
262262
try:
263263
self._serialize(fp)
264264
lfd.commit()
265-
except Exception:
266-
# on failure it rolls back automatically, but we make it clear
265+
except BaseException:
267266
lfd.rollback()
268267
raise
269268
# END handle change

git/refs/symbolic.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,12 @@ def set_reference(
370370

371371
lfd = LockedFD(fpath)
372372
fd = lfd.open(write=True, stream=True)
373-
ok = True
374373
try:
375374
fd.write(write_value.encode("utf-8") + b"\n")
376375
lfd.commit()
377-
ok = True
378-
finally:
379-
if not ok:
380-
lfd.rollback()
376+
except BaseException:
377+
lfd.rollback()
378+
raise
381379
# Adjust the reflog
382380
if logmsg is not None:
383381
self.log_append(oldbinsha, logmsg)

0 commit comments

Comments
 (0)