summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-11-24 17:55:43 +0100
committerSebastian Thiel <byronimo@gmail.com>2010-11-24 18:06:00 +0100
commit86523260c495d9a29aa5ab29d50d30a5d1981a0c (patch)
treefd478570d7f8c33b9d1a10c3f108a170edee3841
parentc946bf260d3f7ca54bffb796a82218dce0eb703f (diff)
downloadgitpython-86523260c495d9a29aa5ab29d50d30a5d1981a0c.tar.gz
Renamed msg named parameter to logmsg, as it describes the purpose of the message much better
Added test for deletion of reflog file when the corresponding ref is deleted
-rw-r--r--refs/reference.py8
-rw-r--r--refs/symbolic.py32
-rw-r--r--test/test_refs.py17
3 files changed, 27 insertions, 30 deletions
diff --git a/refs/reference.py b/refs/reference.py
index c44ebf00..1a745ee9 100644
--- a/refs/reference.py
+++ b/refs/reference.py
@@ -37,17 +37,17 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
def __str__(self):
return self.name
- def set_object(self, object, msg = None):
+ def set_object(self, object, logmsg = None):
"""Special version which checks if the head-log needs an update as well"""
oldbinsha = None
- if msg is not None:
+ if logmsg is not None:
head = self.repo.head
if not head.is_detached and head.ref == self:
oldbinsha = self.commit.binsha
#END handle commit retrieval
#END handle message is set
- super(Reference, self).set_object(object, msg)
+ super(Reference, self).set_object(object, logmsg)
if oldbinsha is not None:
# /* from refs.c in git-source
@@ -62,7 +62,7 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
# * check with HEAD only which should cover 99% of all usage
# * scenarios (even 100% of the default ones).
# */
- self.repo.head.log_append(oldbinsha, msg)
+ self.repo.head.log_append(oldbinsha, logmsg)
#END check if the head
# NOTE: Don't have to overwrite properties as the will only work without a the log
diff --git a/refs/symbolic.py b/refs/symbolic.py
index cdd6158a..f333bd46 100644
--- a/refs/symbolic.py
+++ b/refs/symbolic.py
@@ -172,7 +172,7 @@ class SymbolicReference(object):
#END handle type
return obj
- def set_commit(self, commit, msg = None):
+ def set_commit(self, commit, logmsg = None):
"""As set_object, but restricts the type of object to be a Commit
:raise ValueError: If commit is not a Commit object or doesn't point to
a commit
@@ -196,18 +196,18 @@ class SymbolicReference(object):
#END handle raise
# we leave strings to the rev-parse method below
- self.set_object(commit, msg)
+ self.set_object(commit, logmsg)
return self
- def set_object(self, object, msg = None):
+ def set_object(self, object, logmsg = None):
"""Set the object we point to, possibly dereference our symbolic reference first.
If the reference does not exist, it will be created
:param object: a refspec, a SymbolicReference or an Object instance. SymbolicReferences
will be dereferenced beforehand to obtain the object they point to
- :param msg: If not None, the message will be used in the reflog entry to be
+ :param logmsg: If not None, the message will be used in the reflog entry to be
written. Otherwise the reflog is not altered
:note: plain SymbolicReferences may not actually point to objects by convention
:return: self"""
@@ -223,10 +223,10 @@ class SymbolicReference(object):
# END handle non-existing ones
if is_detached:
- return self.set_reference(object, msg)
+ return self.set_reference(object, logmsg)
# set the commit on our reference
- return self._get_reference().set_object(object, msg)
+ return self._get_reference().set_object(object, logmsg)
commit = property(_get_commit, set_commit, doc="Query or set commits directly")
object = property(_get_object, set_object, doc="Return the object our ref currently refers to")
@@ -240,7 +240,7 @@ class SymbolicReference(object):
raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
return self.from_path(self.repo, target_ref_path)
- def set_reference(self, ref, msg = None):
+ def set_reference(self, ref, logmsg = None):
"""Set ourselves to the given ref. It will stay a symbol if the ref is a Reference.
Otherwise an Object, given as Object instance or refspec, is assumed and if valid,
will be set which effectively detaches the refererence if it was a purely
@@ -249,7 +249,7 @@ class SymbolicReference(object):
:param ref: SymbolicReference instance, Object instance or refspec string
Only if the ref is a SymbolicRef instance, we will point to it. Everthiny
else is dereferenced to obtain the actual object.
- :param msg: If set to a string, the message will be used in the reflog.
+ :param logmsg: If set to a string, the message will be used in the reflog.
Otherwise, a reflog entry is not written for the changed reference.
The previous commit of the entry will be the commit we point to now.
@@ -282,7 +282,7 @@ class SymbolicReference(object):
#END verify type
oldbinsha = None
- if msg is not None:
+ if logmsg is not None:
try:
oldbinsha = self.commit.binsha
except ValueError:
@@ -299,8 +299,8 @@ class SymbolicReference(object):
lfd.commit()
# Adjust the reflog
- if msg is not None:
- self.log_append(oldbinsha, msg)
+ if logmsg is not None:
+ self.log_append(oldbinsha, logmsg)
#END handle reflog
return self
@@ -426,7 +426,7 @@ class SymbolicReference(object):
@classmethod
- def _create(cls, repo, path, resolve, reference, force, msg=None):
+ def _create(cls, repo, path, resolve, reference, force, logmsg=None):
"""internal method used to create a new symbolic reference.
If resolve is False, the reference will be taken as is, creating
a proper symbolic reference. Otherwise it will be resolved to the
@@ -452,11 +452,11 @@ class SymbolicReference(object):
# END no force handling
ref = cls(repo, full_ref_path)
- ref.set_reference(target, msg)
+ ref.set_reference(target, logmsg)
return ref
@classmethod
- def create(cls, repo, path, reference='HEAD', force=False, msg=None):
+ def create(cls, repo, path, reference='HEAD', force=False, logmsg=None):
"""Create a new symbolic reference, hence a reference pointing to another reference.
:param repo:
@@ -473,7 +473,7 @@ class SymbolicReference(object):
if True, force creation even if a symbolic reference with that name already exists.
Raise OSError otherwise
- :param msg:
+ :param logmsg:
If not None, the message to append to the reflog. Otherwise no reflog
entry is written.
@@ -484,7 +484,7 @@ class SymbolicReference(object):
already exists.
:note: This does not alter the current HEAD, index or Working Tree"""
- return cls._create(repo, path, cls._resolve_ref_on_create, reference, force, msg)
+ return cls._create(repo, path, cls._resolve_ref_on_create, reference, force, logmsg)
def rename(self, new_path, force=False):
"""Rename self to a new path
diff --git a/test/test_refs.py b/test/test_refs.py
index 3ad4dad2..52937de1 100644
--- a/test/test_refs.py
+++ b/test/test_refs.py
@@ -102,7 +102,7 @@ class TestRefs(TestBase):
pcommit = cur_head.commit.parents[0].parents[0]
hlog_len = len(head.log())
blog_len = len(cur_head.log())
- head.set_reference(pcommit, 'detached head')
+ assert head.set_reference(pcommit, 'detached head') is head
# one new log-entry
thlog = head.log()
assert len(thlog) == hlog_len + 1
@@ -125,12 +125,12 @@ class TestRefs(TestBase):
# with automatic dereferencing
- head.set_commit(cur_commit, 'change commit once again')
+ assert head.set_commit(cur_commit, 'change commit once again') is head
assert len(head.log()) == hlog_len+4
assert len(cur_head.log()) == blog_len+2
# a new branch has just a single entry
- other_head = Head.create(rwrepo, 'mynewhead', pcommit, msg='new head created')
+ other_head = Head.create(rwrepo, 'mynewhead', pcommit, logmsg='new head created')
log = other_head.log()
assert len(log) == 1
assert log[0].oldhexsha == pcommit.NULL_HEX_SHA
@@ -237,7 +237,11 @@ class TestRefs(TestBase):
tmp_head.rename(new_head, force=True)
assert tmp_head == new_head and tmp_head.object == new_head.object
+ logfile = RefLog.path(tmp_head)
+ assert os.path.isfile(logfile)
Head.delete(rw_repo, tmp_head)
+ # deletion removes the log as well
+ assert not os.path.isfile(logfile)
heads = rw_repo.heads
assert tmp_head not in heads and new_head not in heads
# force on deletion testing would be missing here, code looks okay though ;)
@@ -512,10 +516,3 @@ class TestRefs(TestBase):
def test_reflog(self):
assert isinstance(self.rorepo.heads.master.log(), RefLog)
-
- def test_todo(self):
- # delete deletes the reflog
- # create creates a new entry
- # set_reference and set_commit and set_object use the reflog if message is given
- # if there is no actual head-change, don't do anything
- self.fail()