Skip to content

Commit 15ee0ac

Browse files
committed
IndexFile: unmerged_blobs lists are now sorted
Repo.init: fixed incorrect use of the path which was to optionally specify where to initialize the repository. Update test as well
1 parent 400d728 commit 15ee0ac

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

lib/git/index.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ def unmerged_blobs(self):
672672
Returns
673673
Iterator yielding dict(path : list( tuple( stage, Blob, ...))), being
674674
a dictionary associating a path in the index with a list containing
675-
stage/blob pairs
675+
sorted stage/blob pairs
676676
677677
Note:
678678
Blobs that have been removed in one side simply do not exist in the
@@ -684,7 +684,8 @@ def unmerged_blobs(self):
684684
for stage, blob in self.iter_blobs(is_unmerged_blob):
685685
path_map.setdefault(blob.path, list()).append((stage, blob))
686686
# END for each unmerged blob
687-
687+
for l in path_map.itervalues():
688+
l.sort()
688689
return path_map
689690

690691
@classmethod
@@ -724,7 +725,7 @@ def resolve_blobs(self, iter_blobs):
724725
for blob in iter_blobs:
725726
stage_null_key = (blob.path, 0)
726727
if stage_null_key in self.entries:
727-
raise ValueError( "Blob %r already at stage 0" % blob )
728+
raise ValueError( "Path %r already exists at stage 0" % blob.path )
728729
# END assert blob is not stage 0 already
729730

730731
# delete all possible stages

lib/git/repo.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,9 @@ def init(cls, path=None, mkdir=True, **kwargs):
693693
if mkdir and path and not os.path.exists(path):
694694
os.makedirs(path, 0755)
695695

696+
# git command automatically chdir into the directory
696697
git = Git(path)
697-
output = git.init(path, **kwargs)
698+
output = git.init(**kwargs)
698699
return Repo(path)
699700

700701
def clone(self, path, **kwargs):

test/git/test_repo.py

+28-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from git import *
1010
from git.utils import join_path_native
1111
import tempfile
12+
import shutil
1213

1314
class TestRepo(TestBase):
1415

@@ -90,17 +91,33 @@ def test_trees(self):
9091
assert num_trees == mc
9192

9293

93-
@patch_object(Repo, '__init__')
94-
@patch_object(Git, '_call_process')
95-
def test_init(self, git, repo):
96-
git.return_value = True
97-
repo.return_value = None
98-
99-
r = Repo.init("repos/foo/bar.git", bare=True)
100-
assert isinstance(r, Repo)
101-
102-
assert_true(git.called)
103-
assert_true(repo.called)
94+
def test_init(self):
95+
prev_cwd = os.getcwd()
96+
os.chdir(tempfile.gettempdir())
97+
git_dir_rela = "repos/foo/bar.git"
98+
del_dir_abs = os.path.abspath("repos")
99+
git_dir_abs = os.path.abspath(git_dir_rela)
100+
try:
101+
# with specific path
102+
for path in (git_dir_rela, git_dir_abs):
103+
r = Repo.init(path=path, bare=True)
104+
assert isinstance(r, Repo)
105+
assert r.bare == True
106+
assert os.path.isdir(r.git_dir)
107+
shutil.rmtree(git_dir_abs)
108+
# END for each path
109+
110+
os.makedirs(git_dir_rela)
111+
os.chdir(git_dir_rela)
112+
r = Repo.init(bare=False)
113+
r.bare == False
114+
finally:
115+
try:
116+
shutil.rmtree(del_dir_abs)
117+
except OSError:
118+
pass
119+
os.chdir(prev_cwd)
120+
# END restore previous state
104121

105122
def test_bare_property(self):
106123
self.rorepo.bare

0 commit comments

Comments
 (0)