summaryrefslogtreecommitdiff
path: root/git/objects/submodule
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-21 08:52:23 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-21 08:53:14 +0100
commit47ac37be2e0e14e958ad24dc8cba1fa4b7f78700 (patch)
treec7544cb324a1141628e281828bc4f9bda295ae5c /git/objects/submodule
parentbb0f3d78d6980a1d43f05cb17a8da57a196a34f3 (diff)
downloadgitpython-47ac37be2e0e14e958ad24dc8cba1fa4b7f78700.tar.gz
Assured that branch changes are properly handled.
Previously we could try to remove the branch we are on. Of course, we have a test-case elaborate enough to verify we don't destroy changes in submodules accidentally. Therefore I am confident that this implementation is correct. Fixes #49
Diffstat (limited to 'git/objects/submodule')
-rw-r--r--git/objects/submodule/base.py12
-rw-r--r--git/objects/submodule/root.py25
-rw-r--r--git/objects/submodule/util.py2
3 files changed, 11 insertions, 28 deletions
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index 4b2fc0c0..ebb66495 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -411,21 +411,9 @@ class Submodule(util.IndexObject, Iterable, Traversable):
del(writer)
# we deliberatly assume that our head matches our index !
-
- try:
- repo.head.commit
- parent_repo_is_empty = False
- except ValueError:
- parent_repo_is_empty = True
- # Can't set this yet, if the parent repo is empty.
- # end
sm.binsha = mrepo.head.commit.binsha
index.add([sm], write=True)
- if parent_repo_is_empty:
- log.debug("Will not set _parent_commit now as the parent repository has no commit yet.")
- # end
-
return sm
def update(self, recursive=False, init=True, to_latest_revision=False, progress=None, dry_run=False,
diff --git a/git/objects/submodule/root.py b/git/objects/submodule/root.py
index 7042e99c..1c863f6f 100644
--- a/git/objects/submodule/root.py
+++ b/git/objects/submodule/root.py
@@ -287,6 +287,11 @@ class RootModule(Submodule):
if not dry_run:
smm = sm.module()
smmr = smm.remotes
+ # As the branch might not exist yet, we will have to fetch all remotes to be sure ... .
+ for remote in smmr:
+ remote.fetch(progress=progress)
+ # end for each remote
+
try:
tbr = git.Head.create(smm, sm.branch_name, logmsg='branch: Created from HEAD')
except OSError:
@@ -295,21 +300,11 @@ class RootModule(Submodule):
# END assure tracking branch exists
tbr.set_tracking_branch(find_first_remote_branch(smmr, sm.branch_name))
- # figure out whether the previous tracking branch contains
- # new commits compared to the other one, if not we can
- # delete it.
- try:
- tbr = find_first_remote_branch(smmr, psm.branch_name)
- if len(smm.git.cherry(tbr, psm.branch)) == 0:
- psm.branch.delete(smm, psm.branch)
- # END delete original tracking branch if there are no changes
- except InvalidGitRepositoryError:
- # ignore it if the previous branch couldn't be found in the
- # current remotes, this just means we can't handle it
- pass
- # END exception handling
-
- # NOTE: All checkout is done in the base implementation of update
+ # NOTE: All head-resetting is done in the base implementation of update
+ # but we will have to checkout the new branch here. As it still points to the currently
+ # checkout out commit, we don't do any harm.
+ # As we don't want to update working-tree or index, changing the ref is all there is to do
+ smm.head.reference = tbr
# END handle dry_run
progress.update(
diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py
index 5604dec7..8b9873fc 100644
--- a/git/objects/submodule/util.py
+++ b/git/objects/submodule/util.py
@@ -49,7 +49,7 @@ def find_first_remote_branch(remotes, branch_name):
continue
# END exception handling
# END for remote
- raise InvalidGitRepositoryError("Didn't find remote branch %r in any of the given remotes", branch_name)
+ raise InvalidGitRepositoryError("Didn't find remote branch '%r' in any of the given remotes" % branch_name)
#} END utilities