summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-11-24 22:53:24 +0100
committerSebastian Thiel <byronimo@gmail.com>2010-11-24 22:53:24 +0100
commitcf1d5bd4208514bab3e6ee523a70dff8176c8c80 (patch)
treed68f6529275838b9a962c4b76533e8445441af34
parent3175b5b21194bcc8f4448abe0a03a98d3a4a1360 (diff)
parent7da101ba9a09a22a85c314a8909fd23468ae66f0 (diff)
downloadgitpython-cf1d5bd4208514bab3e6ee523a70dff8176c8c80.tar.gz
Merge branch 'reflogintegration'
-rw-r--r--doc/source/changes.rst10
-rw-r--r--index/base.py18
-rw-r--r--objects/commit.py20
-rw-r--r--objects/submodule/base.py2
-rw-r--r--objects/submodule/root.py28
-rw-r--r--repo/base.py4
-rw-r--r--repo/fun.py6
-rw-r--r--test/test_refs.py3
-rw-r--r--test/test_repo.py2
9 files changed, 61 insertions, 32 deletions
diff --git a/doc/source/changes.rst b/doc/source/changes.rst
index 7b959532..d820c8ca 100644
--- a/doc/source/changes.rst
+++ b/doc/source/changes.rst
@@ -17,9 +17,17 @@ Changelog
* ``set_commit(...)`` method added (reflog support)
* ``set_object(...)`` method added (reflog support)
- * Intrusive Changes to ``Head`` type
+ * **Intrusive Changes** to ``Head`` type
* ``create(...)`` method now supports the reflog, but will not raise ``GitCommandError`` anymore as it is a pure python implementation now. Instead, it raises ``OSError``.
+
+ * **Intrusive Changes** to ``Actor`` type
+
+ * the *name* field is now using unicode if ascii does not match
+
+ * **Intrusive Changes** to ``Repo`` type
+
+ * ``create_head(...)`` method does not support **kwargs anymore, instead it supports a logmsg parameter
* Repo.rev_parse now supports the [ref]@{n} syntax, where n is the number of steps to look into the reference's past
diff --git a/index/base.py b/index/base.py
index a63dbb26..d813e6c1 100644
--- a/index/base.py
+++ b/index/base.py
@@ -933,7 +933,14 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
If one of files or directories do not exist in the index
( as opposed to the original git command who ignores them ).
Raise GitCommandError if error lines could not be parsed - this truly is
- an exceptional state"""
+ an exceptional state
+
+ .. note:: The checkout is limited to checking out the files in the
+ index. Files which are not in the index anymore and exist in
+ the working tree will not be deleted. This behaviour is fundamentally
+ different to *head.checkout*, i.e. if you want git-checkout like behaviour,
+ use head.checkout instead of index.checkout.
+ """
args = ["--index"]
if force:
args.append("--force")
@@ -1055,7 +1062,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
If False, the working tree will not be touched
Please note that changes to the working copy will be discarded without
warning !
-
+
:param head:
If True, the head will be set to the given commit. This is False by default,
but if True, this method behaves like HEAD.reset.
@@ -1067,6 +1074,11 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
:param kwargs:
Additional keyword arguments passed to git-reset
+
+ .. note:: IndexFile.reset, as opposed to HEAD.reset, will not delete anyfiles
+ in order to maintain a consistent working tree. Instead, it will just
+ checkout the files according to their state in the index.
+ If you want git-reset like behaviour, use *HEAD.reset* instead.
:return: self """
# what we actually want to do is to merge the tree into our existing
@@ -1098,7 +1110,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# END handle working tree
if head:
- self.repo.head.commit = self.repo.commit(commit)
+ self.repo.head.set_commit(self.repo.commit(commit), logmsg="%s: Updating HEAD" % commit)
# END handle head change
return self
diff --git a/objects/commit.py b/objects/commit.py
index 9c7e66a3..69a3adc4 100644
--- a/objects/commit.py
+++ b/objects/commit.py
@@ -350,13 +350,13 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# as well ...
import git.refs
try:
- repo.head.commit = new_commit
+ repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
except ValueError:
# head is not yet set to the ref our HEAD points to
# Happens on first commit
import git.refs
- master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit)
- repo.head.reference = master
+ master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit, logmsg="commit (initial): %s" % message)
+ repo.head.set_reference(master, logmsg='commit: Switching to %s' % master)
# END handle empty repositories
# END advance head handling
@@ -382,7 +382,12 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
self.authored_date,
altz_to_utctz_str(self.author_tz_offset)))
- write(fmt % ("committer", c.name, c.email,
+ # encode committer
+ aname = c.name
+ if isinstance(aname, unicode):
+ aname = aname.encode(self.encoding)
+ # END handle unicode in name
+ write(fmt % ("committer", aname, c.email,
self.committed_date,
altz_to_utctz_str(self.committer_tz_offset)))
@@ -440,6 +445,13 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
print >> sys.stderr, "Failed to decode author name '%s' using encoding %s" % (self.author.name, self.encoding)
# END handle author's encoding
+ # decode committer name
+ try:
+ self.committer.name = self.committer.name.decode(self.encoding)
+ except UnicodeDecodeError:
+ print >> sys.stderr, "Failed to decode committer name '%s' using encoding %s" % (self.committer.name, self.encoding)
+ # END handle author's encoding
+
# a stream from our data simply gives us the plain message
# The end of our message stream is marked with a newline that we strip
self.message = stream.read()
diff --git a/objects/submodule/base.py b/objects/submodule/base.py
index 5d32d600..36b48d78 100644
--- a/objects/submodule/base.py
+++ b/objects/submodule/base.py
@@ -344,7 +344,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
# END initial checkout + branch creation
# make sure HEAD is not detached
- mrepo.head.ref = local_branch
+ mrepo.head.set_reference(local_branch, logmsg="submodule: attaching head to %s" % local_branch)
mrepo.head.ref.set_tracking_branch(remote_branch)
except IndexError:
print >> sys.stderr, "Warning: Failed to checkout tracking branch %s" % self.branch_path
diff --git a/objects/submodule/root.py b/objects/submodule/root.py
index d194cd5b..753c6df4 100644
--- a/objects/submodule/root.py
+++ b/objects/submodule/root.py
@@ -68,19 +68,15 @@ class RootModule(Submodule):
##################
cur_commit = repo.head.commit
if previous_commit is None:
- symref = repo.head.orig_head()
try:
- previous_commit = symref.commit
- except Exception:
- pcommits = cur_commit.parents
- if pcommits:
- previous_commit = pcommits[0]
- else:
- # in this special case, we just diff against ourselve, which
- # means exactly no change
- previous_commit = cur_commit
- # END handle initial commit
- # END no ORIG_HEAD
+ previous_commit = repo.commit(repo.head.log_entry(-1).oldhexsha)
+ if previous_commit.binsha == previous_commit.NULL_BIN_SHA:
+ raise IndexError
+ #END handle initial commit
+ except IndexError:
+ # in new repositories, there is no previous commit
+ previous_commit = cur_commit
+ #END exception handling
else:
previous_commit = repo.commit(previous_commit) # obtain commit object
# END handle previous commit
@@ -207,12 +203,8 @@ class RootModule(Submodule):
smm = sm.module()
smmr = smm.remotes
try:
- tbr = git.Head.create(smm, sm.branch_name)
- except git.GitCommandError, e:
- if e.status != 128:
- raise
- #END handle something unexpected
-
+ tbr = git.Head.create(smm, sm.branch_name, logmsg='branch: Created from HEAD')
+ except OSError:
# ... or reuse the existing one
tbr = git.Head(smm, sm.branch_path)
#END assure tracking branch exists
diff --git a/repo/base.py b/repo/base.py
index c8613878..e26da101 100644
--- a/repo/base.py
+++ b/repo/base.py
@@ -274,12 +274,12 @@ class Repo(object):
:param path: path to the tag reference, i.e. 0.1.5 or tags/0.1.5 """
return TagReference(self, path)
- def create_head(self, path, commit='HEAD', force=False, **kwargs ):
+ def create_head(self, path, commit='HEAD', force=False, logmsg=None ):
"""Create a new head within the repository.
For more documentation, please see the Head.create method.
:return: newly created Head Reference"""
- return Head.create(self, path, commit, force, **kwargs)
+ return Head.create(self, path, commit, force, logmsg)
def delete_head(self, *heads, **kwargs):
"""Delete the given heads
diff --git a/repo/fun.py b/repo/fun.py
index c523a3e1..7a5984d3 100644
--- a/repo/fun.py
+++ b/repo/fun.py
@@ -112,7 +112,9 @@ def rev_parse(repo, rev):
for details
:note: Currently there is no access to the rev-log, rev-specs may only contain
topological tokens such ~ and ^.
- :raise BadObject: if the given revision could not be found"""
+ :raise BadObject: if the given revision could not be found
+ :raise ValueError: If rev couldn't be parsed
+ :raise IndexError: If invalid reflog index is specified"""
# colon search mode ?
if rev.startswith(':/'):
@@ -193,7 +195,7 @@ def rev_parse(repo, rev):
try:
entry = ref.log_entry(revlog_index)
except IndexError:
- raise BadObject("Invalid revlog index: %i" % revlog_index)
+ raise IndexError("Invalid revlog index: %i" % revlog_index)
#END handle index out of bound
obj = Object.new_from_sha(repo, hex_to_bin(entry.newhexsha))
diff --git a/test/test_refs.py b/test/test_refs.py
index 52937de1..2338b4e4 100644
--- a/test/test_refs.py
+++ b/test/test_refs.py
@@ -149,6 +149,9 @@ class TestRefs(TestBase):
assert self.rorepo.head.reference.is_valid()
assert SymbolicReference(self.rorepo, 'hellothere').is_valid() == False
+ def test_orig_head(self):
+ assert type(self.rorepo.head.orig_head()) == SymbolicReference
+
@with_rw_repo('0.1.6')
def test_head_reset(self, rw_repo):
cur_head = rw_repo.head
diff --git a/test/test_repo.py b/test/test_repo.py
index 95b0750a..f517b9f1 100644
--- a/test/test_repo.py
+++ b/test/test_repo.py
@@ -568,7 +568,7 @@ class TestRepo(TestBase):
assert rev_parse('@{1}') != head.commit
# position doesn't exist
- self.failUnlessRaises(BadObject, rev_parse, '@{10000}')
+ self.failUnlessRaises(IndexError, rev_parse, '@{10000}')
# currently, nothing more is supported
self.failUnlessRaises(NotImplementedError, rev_parse, "@{1 week ago}")