Skip to content

git-add doesn't seem to work on submodules #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kgadek opened this issue Aug 6, 2015 · 6 comments
Closed

git-add doesn't seem to work on submodules #335

kgadek opened this issue Aug 6, 2015 · 6 comments
Assignees

Comments

@kgadek
Copy link

kgadek commented Aug 6, 2015

It seems that index.add doesn't work with submodules. Found exactly same issue/question on stackoverflow.

Reproduction

First, some shell:

git init master_repo
cd master_repo
echo "First" > progress_simulator
git add progress_simulator
git commit -m 'First commit'
git submodule add -b master [email protected]:gitpython-developers/GitPython.git subrepo
git commit -m 'Second commit: subrepo'

Now, the Python:

import git
master_repo = git.Repo('.')
[subrepo_sm] = master_repo.submodules
subrepo = git.Repo(subrepo_sm.path)
with open('subrepo/interference.txt', 'w'): pass
subrepo.index.add(['interference.txt'])
subrepo.index.commit('My intrusion into this project')
master_repo.index.add([subrepo_sm])

Expected vs result

I expected to see master_repo index acknowledge that the subrepo submodule pointer changed. However, nothing happens.

System info

$ python -V
Python 3.4.3

$ git --version
git version 2.4.2
@Byron Byron added this to the v1.0.2 - Fixes milestone Aug 8, 2015
@Byron Byron self-assigned this Aug 8, 2015
@Byron
Copy link
Member

Byron commented Aug 8, 2015

Thanks for the awesome issue ! I wished all of them would be made that thoroughly !

Even though I am working on figuring out the GitPython way, one should always be able to use git directly such as in master_repo.git.add(subrepo_sm.path), which will add the submodule correctly. Now one will be able to commit the staged changes.

I shall keep you posted.

Byron added a commit that referenced this issue Aug 8, 2015
It's somewhat more complex to add new commits in submodules to the
parent repository. The new test shows how to do that in a 'GitPythonic'
way.

Related to #335
@Byron
Copy link
Member

Byron commented Aug 8, 2015

There now is a new test which shows how to do it in a pythonic fashion. The stackoverflow question was answered showing the mentioned way, and a slightly simpler one.

Both ways show that a change in GitPython is not required, even though adding changed submodules to the index seems a bit more difficult/involved than one might hope when using GitPython directly.

@Byron Byron closed this as completed Aug 8, 2015
@kgadek
Copy link
Author

kgadek commented Aug 8, 2015

Thanks! I'll look at it tomorrow :)

@Byron
Copy link
Member

Byron commented Aug 8, 2015

That's a good idea ! Apparently the approach only works in py2.6 - travis fails in all other versions. It's ... odd.

@Byron Byron reopened this Aug 8, 2015
@Byron Byron closed this as completed in 039e265 Aug 8, 2015
@Byron
Copy link
Member

Byron commented Aug 8, 2015

Ok, just a bug in the test - I think chances are travis will confirm this is fixed now.

@Byron
Copy link
Member

Byron commented Aug 8, 2015

You can watch the development stream on youtube.

GitPython #19 [issue 335 - how to add submodules to the index]

thumb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants