Skip to content

create_submodule fails on existing submodule #678

Closed
@jakirkham

Description

@jakirkham

Based on the docs for create_submodule, it sounds like it proceeds through Submodule.add. According to the docs for Submodule.add, it sounds like add should still work fine if the submodule already exists. However that does not appear to be the case. Have included an example of the issue experienced below along with details about how to create an environment where this issue can be reproduced.

Example:

In [1]: import os

In [2]: import git

In [3]: r = git.Repo.clone_from("https://github.com/conda-forge/feedstocks", "feedstocks")

In [4]: r.create_submodule(name="addict", path=os.path.join("feedstocks", "addict"), url="https://github.com/conda-forge/addict-feedstock", branch="master")
Out[4]: ---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/zopt/conda2/envs/test/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

/zopt/conda2/envs/test/lib/python3.6/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    393                             if callable(meth):
    394                                 return meth(obj, self, cycle)
--> 395             return _default_pprint(obj, self, cycle)
    396         finally:
    397             self.end_group()

/zopt/conda2/envs/test/lib/python3.6/site-packages/IPython/lib/pretty.py in _default_pprint(obj, p, cycle)
    508     if _safe_getattr(klass, '__repr__', None) is not object.__repr__:
    509         # A user-provided repr. Find newlines and replace them with p.break_()
--> 510         _repr_pprint(obj, p, cycle)
    511         return
    512     p.begin_group(1, '<')

/zopt/conda2/envs/test/lib/python3.6/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    699     """A pprint that just redirects to the normal repr function."""
    700     # Find newlines and replace them with p.break_()
--> 701     output = repr(obj)
    702     for idx,output_line in enumerate(output.splitlines()):
    703         if idx:

/zopt/conda2/envs/test/lib/python3.6/site-packages/git/objects/submodule/base.py in __repr__(self)
    170     def __repr__(self):
    171         return "git.%s(name=%s, path=%s, url=%s, branch_path=%s)"\
--> 172                % (type(self).__name__, self._name, self.path, self.url, self.branch_path)
    173 
    174     @classmethod

/zopt/conda2/envs/test/lib/python3.6/site-packages/gitdb/util.py in __getattr__(self, attr)
    254         to be created and set. Next time the same attribute is reqeusted, it is simply
    255         returned from our dict/slots. """
--> 256         self._set_cache_(attr)
    257         # will raise in case the cache was not created
    258         return object.__getattribute__(self, attr)

/zopt/conda2/envs/test/lib/python3.6/site-packages/git/objects/submodule/base.py in _set_cache_(self, attr)
    133             self._branch_path = reader.get_value(self.k_head_option, git.Head.to_full_path(self.k_head_default))
    134         elif attr == '_name':
--> 135             raise AttributeError("Cannot retrieve the name of a submodule if it was not set initially")
    136         else:
    137             super(Submodule, self)._set_cache_(attr)

AttributeError: Cannot retrieve the name of a submodule if it was not set initially

Environment (with conda):

# environment.yaml
name: test
channels:
- nanshe
- conda-forge
- defaults
dependencies:
- appnope=0.1.0=py36_0
- ca-certificates=2017.7.27.1=0
- certifi=2017.7.27.1=py36_0
- decorator=4.1.2=py36_0
- gitdb2=2.0.2=py36_0
- gitpython=2.1.5=py36_0
- ipython=6.2.1=py36_0
- ipython_genutils=0.2.0=py36_0
- jedi=0.10.2=py36_0
- ncurses=5.9=10
- openssl=1.0.2l=0
- pexpect=4.2.1=py36_0
- pickleshare=0.7.4=py36_0
- pip=9.0.1=py36_0
- prompt_toolkit=1.0.15=py36_0
- ptyprocess=0.5.2=py36_0
- pygments=2.2.0=py36_0
- python=3.6.2=0
- readline=6.2=0
- setuptools=36.3.0=py36_0
- simplegeneric=0.8.1=py36_0
- six=1.11.0=py36_1
- smmap2=2.0.3=py36_0
- sqlite=3.13.0=1
- tk=8.5.19=2
- traitlets=4.3.2=py36_0
- wcwidth=0.1.7=py36_0
- wheel=0.30.0=py_1
- xz=5.2.3=0
- zlib=1.2.11=0

FWIW relevant entry in .gitmodules:

...
[submodule "addict"]
	path = feedstocks/addict
	url = https://github.com/conda-forge/addict-feedstock.git
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions