summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/objects/submodule.py46
-rw-r--r--test/git/test_submodule.py9
2 files changed, 35 insertions, 20 deletions
diff --git a/lib/git/objects/submodule.py b/lib/git/objects/submodule.py
index d58e07a9..72ab6360 100644
--- a/lib/git/objects/submodule.py
+++ b/lib/git/objects/submodule.py
@@ -144,6 +144,9 @@ class Submodule(base.IndexObject, Iterable, Traversable):
"""Hash this instance using its logical id, not the sha"""
return hash(self._name)
+ def __str__(self):
+ return self._name
+
@classmethod
def _config_parser(cls, repo, parent_commit, read_only):
""":return: Config Parser constrained to our submodule in read or write mode
@@ -250,20 +253,24 @@ class Submodule(base.IndexObject, Iterable, Traversable):
remote_branch = mrepo.remotes.origin.refs[self.branch]
local_branch = git.Head(mrepo, git.Head.to_full_path(self.branch))
if not local_branch.is_valid():
- mrepo.git.checkout(remote_branch, b=self.branch)
- else:
- # have a valid branch, but no checkout - make sure we can figure
- # that out by marking the commit with a null_sha
- # have to write it directly as .commit = NULLSHA tries to resolve the sha
- ref = mrepo.head.ref
- refpath = join_path_native(mrepo.git_dir, ref.to_full_path(ref.path))
- refdir = os.path.dirname(refpath)
- if not os.path.isdir(refdir):
- os.makedirs(refdir)
- #END handle directory
- open(refpath, 'w').write(self.NULL_HEX_SHA)
+ # Setup a tracking configuration - branch doesn't need to
+ # exist to do that
+ local_branch.set_tracking_branch(remote_branch)
+ #END handle local branch
+
+ # have a valid branch, but no checkout - make sure we can figure
+ # that out by marking the commit with a null_sha
+ # have to write it directly as .commit = NULLSHA tries to resolve the sha
+ # This will bring the branch into existance
+ refpath = join_path_native(mrepo.git_dir, local_branch.path)
+ refdir = os.path.dirname(refpath)
+ if not os.path.isdir(refdir):
+ os.makedirs(refdir)
+ #END handle directory
+ open(refpath, 'w').write(self.NULL_HEX_SHA)
# END initial checkout + branch creation
- # make sure we are not detached
+
+ # make sure HEAD is not detached
mrepo.head.ref = local_branch
except IndexError:
print >> sys.stderr, "Warning: Failed to checkout tracking branch %s" % self.branch
@@ -280,13 +287,14 @@ class Submodule(base.IndexObject, Iterable, Traversable):
# branch - this should be prevented when setting the branch option
mrepo.head.reset(self.hexsha, index=True, working_tree=True)
# END handle checkout
-
- if recursive:
- for submodule in self.iter_items(self.module()):
- submodule.update(recursive, init)
- # END handle recursive update
- # END for each submodule
# END update to new commit only if needed
+
+ # HANDLE RECURSION
+ if recursive:
+ for submodule in self.iter_items(self.module()):
+ submodule.update(recursive, init)
+ # END handle recursive update
+ # END for each submodule
return self
diff --git a/test/git/test_submodule.py b/test/git/test_submodule.py
index 5b1cad6c..40836e1b 100644
--- a/test/git/test_submodule.py
+++ b/test/git/test_submodule.py
@@ -82,6 +82,8 @@ class TestSubmodule(TestBase):
# TEST TODO: if a path in the gitmodules file, but not in the index, it raises
+ # TEST UPDATE
+ ##############
# module retrieval is not always possible
if rwrepo.bare:
self.failUnlessRaises(InvalidGitRepositoryError, sm.module)
@@ -106,6 +108,9 @@ class TestSubmodule(TestBase):
assert isinstance(sm.module(), git.Repo)
assert sm.module().working_tree_dir == sm.module_path()
+ # we should have setup a tracking branch, which is also active
+ assert sm.module().head.ref.tracking_branch() is not None
+
# delete the whole directory and re-initialize
shutil.rmtree(sm.module_path())
sm.update(recursive=False)
@@ -119,10 +124,12 @@ class TestSubmodule(TestBase):
csm.config_writer().set_value('url', new_csm_path)
assert csm.url == new_csm_path
-
# update recuesively again
sm.update(recursive=True)
+ # tracking branch once again
+ csm.module().head.ref.tracking_branch() is not None
+
# this flushed in a sub-submodule
assert len(list(rwrepo.iter_submodules())) == 2
# END handle bare mode