Skip to content

Commit cf1d5bd

Browse files
committed
Merge branch 'reflogintegration'
2 parents 3175b5b + 7da101b commit cf1d5bd

File tree

9 files changed

+61
-32
lines changed

9 files changed

+61
-32
lines changed

doc/source/changes.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ Changelog
1717
* ``set_commit(...)`` method added (reflog support)
1818
* ``set_object(...)`` method added (reflog support)
1919

20-
* Intrusive Changes to ``Head`` type
20+
* **Intrusive Changes** to ``Head`` type
2121

2222
* ``create(...)`` method now supports the reflog, but will not raise ``GitCommandError`` anymore as it is a pure python implementation now. Instead, it raises ``OSError``.
23+
24+
* **Intrusive Changes** to ``Actor`` type
25+
26+
* the *name* field is now using unicode if ascii does not match
27+
28+
* **Intrusive Changes** to ``Repo`` type
29+
30+
* ``create_head(...)`` method does not support **kwargs anymore, instead it supports a logmsg parameter
2331
2432
* Repo.rev_parse now supports the [ref]@{n} syntax, where n is the number of steps to look into the reference's past
2533

index/base.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,14 @@ def checkout(self, paths=None, force=False, fprogress=lambda *args: None, **kwar
933933
If one of files or directories do not exist in the index
934934
( as opposed to the original git command who ignores them ).
935935
Raise GitCommandError if error lines could not be parsed - this truly is
936-
an exceptional state"""
936+
an exceptional state
937+
938+
.. note:: The checkout is limited to checking out the files in the
939+
index. Files which are not in the index anymore and exist in
940+
the working tree will not be deleted. This behaviour is fundamentally
941+
different to *head.checkout*, i.e. if you want git-checkout like behaviour,
942+
use head.checkout instead of index.checkout.
943+
"""
937944
args = ["--index"]
938945
if force:
939946
args.append("--force")
@@ -1055,7 +1062,7 @@ def reset(self, commit='HEAD', working_tree=False, paths=None, head=False, **kwa
10551062
If False, the working tree will not be touched
10561063
Please note that changes to the working copy will be discarded without
10571064
warning !
1058-
1065+
10591066
:param head:
10601067
If True, the head will be set to the given commit. This is False by default,
10611068
but if True, this method behaves like HEAD.reset.
@@ -1067,6 +1074,11 @@ def reset(self, commit='HEAD', working_tree=False, paths=None, head=False, **kwa
10671074
10681075
:param kwargs:
10691076
Additional keyword arguments passed to git-reset
1077+
1078+
.. note:: IndexFile.reset, as opposed to HEAD.reset, will not delete anyfiles
1079+
in order to maintain a consistent working tree. Instead, it will just
1080+
checkout the files according to their state in the index.
1081+
If you want git-reset like behaviour, use *HEAD.reset* instead.
10701082
10711083
:return: self """
10721084
# what we actually want to do is to merge the tree into our existing
@@ -1098,7 +1110,7 @@ def reset(self, commit='HEAD', working_tree=False, paths=None, head=False, **kwa
10981110
# END handle working tree
10991111

11001112
if head:
1101-
self.repo.head.commit = self.repo.commit(commit)
1113+
self.repo.head.set_commit(self.repo.commit(commit), logmsg="%s: Updating HEAD" % commit)
11021114
# END handle head change
11031115

11041116
return self

objects/commit.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,13 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
350350
# as well ...
351351
import git.refs
352352
try:
353-
repo.head.commit = new_commit
353+
repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
354354
except ValueError:
355355
# head is not yet set to the ref our HEAD points to
356356
# Happens on first commit
357357
import git.refs
358-
master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit)
359-
repo.head.reference = master
358+
master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit, logmsg="commit (initial): %s" % message)
359+
repo.head.set_reference(master, logmsg='commit: Switching to %s' % master)
360360
# END handle empty repositories
361361
# END advance head handling
362362

@@ -382,7 +382,12 @@ def _serialize(self, stream):
382382
self.authored_date,
383383
altz_to_utctz_str(self.author_tz_offset)))
384384

385-
write(fmt % ("committer", c.name, c.email,
385+
# encode committer
386+
aname = c.name
387+
if isinstance(aname, unicode):
388+
aname = aname.encode(self.encoding)
389+
# END handle unicode in name
390+
write(fmt % ("committer", aname, c.email,
386391
self.committed_date,
387392
altz_to_utctz_str(self.committer_tz_offset)))
388393

@@ -440,6 +445,13 @@ def _deserialize(self, stream):
440445
print >> sys.stderr, "Failed to decode author name '%s' using encoding %s" % (self.author.name, self.encoding)
441446
# END handle author's encoding
442447

448+
# decode committer name
449+
try:
450+
self.committer.name = self.committer.name.decode(self.encoding)
451+
except UnicodeDecodeError:
452+
print >> sys.stderr, "Failed to decode committer name '%s' using encoding %s" % (self.committer.name, self.encoding)
453+
# END handle author's encoding
454+
443455
# a stream from our data simply gives us the plain message
444456
# The end of our message stream is marked with a newline that we strip
445457
self.message = stream.read()

objects/submodule/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False):
344344
# END initial checkout + branch creation
345345

346346
# make sure HEAD is not detached
347-
mrepo.head.ref = local_branch
347+
mrepo.head.set_reference(local_branch, logmsg="submodule: attaching head to %s" % local_branch)
348348
mrepo.head.ref.set_tracking_branch(remote_branch)
349349
except IndexError:
350350
print >> sys.stderr, "Warning: Failed to checkout tracking branch %s" % self.branch_path

objects/submodule/root.py

+10-18
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,15 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
6868
##################
6969
cur_commit = repo.head.commit
7070
if previous_commit is None:
71-
symref = repo.head.orig_head()
7271
try:
73-
previous_commit = symref.commit
74-
except Exception:
75-
pcommits = cur_commit.parents
76-
if pcommits:
77-
previous_commit = pcommits[0]
78-
else:
79-
# in this special case, we just diff against ourselve, which
80-
# means exactly no change
81-
previous_commit = cur_commit
82-
# END handle initial commit
83-
# END no ORIG_HEAD
72+
previous_commit = repo.commit(repo.head.log_entry(-1).oldhexsha)
73+
if previous_commit.binsha == previous_commit.NULL_BIN_SHA:
74+
raise IndexError
75+
#END handle initial commit
76+
except IndexError:
77+
# in new repositories, there is no previous commit
78+
previous_commit = cur_commit
79+
#END exception handling
8480
else:
8581
previous_commit = repo.commit(previous_commit) # obtain commit object
8682
# END handle previous commit
@@ -207,12 +203,8 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
207203
smm = sm.module()
208204
smmr = smm.remotes
209205
try:
210-
tbr = git.Head.create(smm, sm.branch_name)
211-
except git.GitCommandError, e:
212-
if e.status != 128:
213-
raise
214-
#END handle something unexpected
215-
206+
tbr = git.Head.create(smm, sm.branch_name, logmsg='branch: Created from HEAD')
207+
except OSError:
216208
# ... or reuse the existing one
217209
tbr = git.Head(smm, sm.branch_path)
218210
#END assure tracking branch exists

repo/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,12 @@ def tag(self,path):
274274
:param path: path to the tag reference, i.e. 0.1.5 or tags/0.1.5 """
275275
return TagReference(self, path)
276276

277-
def create_head(self, path, commit='HEAD', force=False, **kwargs ):
277+
def create_head(self, path, commit='HEAD', force=False, logmsg=None ):
278278
"""Create a new head within the repository.
279279
For more documentation, please see the Head.create method.
280280
281281
:return: newly created Head Reference"""
282-
return Head.create(self, path, commit, force, **kwargs)
282+
return Head.create(self, path, commit, force, logmsg)
283283

284284
def delete_head(self, *heads, **kwargs):
285285
"""Delete the given heads

repo/fun.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ def rev_parse(repo, rev):
112112
for details
113113
:note: Currently there is no access to the rev-log, rev-specs may only contain
114114
topological tokens such ~ and ^.
115-
:raise BadObject: if the given revision could not be found"""
115+
:raise BadObject: if the given revision could not be found
116+
:raise ValueError: If rev couldn't be parsed
117+
:raise IndexError: If invalid reflog index is specified"""
116118

117119
# colon search mode ?
118120
if rev.startswith(':/'):
@@ -193,7 +195,7 @@ def rev_parse(repo, rev):
193195
try:
194196
entry = ref.log_entry(revlog_index)
195197
except IndexError:
196-
raise BadObject("Invalid revlog index: %i" % revlog_index)
198+
raise IndexError("Invalid revlog index: %i" % revlog_index)
197199
#END handle index out of bound
198200

199201
obj = Object.new_from_sha(repo, hex_to_bin(entry.newhexsha))

test/test_refs.py

+3
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def test_is_valid(self):
149149
assert self.rorepo.head.reference.is_valid()
150150
assert SymbolicReference(self.rorepo, 'hellothere').is_valid() == False
151151

152+
def test_orig_head(self):
153+
assert type(self.rorepo.head.orig_head()) == SymbolicReference
154+
152155
@with_rw_repo('0.1.6')
153156
def test_head_reset(self, rw_repo):
154157
cur_head = rw_repo.head

test/test_repo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def test_rev_parse(self):
568568
assert rev_parse('@{1}') != head.commit
569569

570570
# position doesn't exist
571-
self.failUnlessRaises(BadObject, rev_parse, '@{10000}')
571+
self.failUnlessRaises(IndexError, rev_parse, '@{10000}')
572572

573573
# currently, nothing more is supported
574574
self.failUnlessRaises(NotImplementedError, rev_parse, "@{1 week ago}")

0 commit comments

Comments
 (0)