Skip to content

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

Description

@kgadek

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 git@github.com: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

Activity

  1. added this to the v1.0.2 - Fixes milestone on Aug 8, 2015
  2. self-assigned this
    on Aug 8, 2015
  3. Byron commented on Aug 8, 2015

    @Byron
    Member

    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.

  4. Byron commented on Aug 8, 2015

    @Byron
    Member

    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.

  5. kgadek commented on Aug 8, 2015

    @kgadek
    Author

    Thanks! I'll look at it tomorrow :)

  6. Byron commented on Aug 8, 2015

    @Byron
    Member

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

  7. reopened this on Aug 8, 2015
  8. Byron commented on Aug 8, 2015

    @Byron
    Member

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

  9. Byron commented on Aug 8, 2015

    @Byron
    Member

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions