diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-01-21 08:52:23 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-01-21 08:53:14 +0100 |
commit | 47ac37be2e0e14e958ad24dc8cba1fa4b7f78700 (patch) | |
tree | c7544cb324a1141628e281828bc4f9bda295ae5c /git/objects/submodule/root.py | |
parent | bb0f3d78d6980a1d43f05cb17a8da57a196a34f3 (diff) | |
download | gitpython-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/root.py')
-rw-r--r-- | git/objects/submodule/root.py | 25 |
1 files changed, 10 insertions, 15 deletions
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( |