GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Submodule from relative URL · Issue #730 · gitpython-developers/GitPython

Submodule from relative URL #730

New issue
Copy link
New issue
Copy link
Closed
#2051
Closed
Submodule from relative URL#730
#2051
Copy link
Labels
acknowledged

Description

@sp-ricard-valverde
sp-ricard-valverde
opened on Feb 27, 2018
Issue body actions

Git submodules allow relative URLs which are based on the parent repo URL.

Right now this is not supported, ie. adding a submodule configuration in .gitmodules with a relative URL will fail when cloning in the add or update Submodule.

A sample stack trace when calling submodule.update(init=True):

GitCommandError
Cmd('git') failed due to: exit code(128)
  cmdline: git clone -n --separate-git-dir=/opt/parent_project/.git/modules/submodule_project -v ../../my-company/submodule-project.git /opt/parent_project/submodule_project
  stderr: 'fatal: repository '../../my-company/submodule-project.git' does not exist
'
git/cmd.py in wait at line 291
git/util.py in finalize_process at line 341
git/repo/base.py in _clone at line 880
git/repo/base.py in clone_from at line 925
git/objects/submodule/base.py in _clone_repo at line 261
git/objects/submodule/base.py in update at line 524

GitPython==2.1.1
Still present in the current revision 8f76463

Reacted by Philipp Hasper, Rok Roškar, Bruceforce, Sam Fuller, Alexander Zhogov and PhilippSelenium

Activity

  1. Byron
    added
    acknowledged
    on Mar 17, 2018
  2. PhilLab commented on Oct 8, 2018

    @PhilLab
    PhilLab
    on Oct 8, 2018
    More actions

    Similar but slightly different message in our system, when calling

    REPO = Repo(ARGS.repositoryPath)
    REPO.submodule_update(recursive=True)
    
    File "C:\Program Files\Python36\lib\site-packages\git\repo\base.py", line 353, in submodule_update
        return RootModule(self).update(*args, **kwargs)
      File "C:\Program Files\Python36\lib\site-packages\git\objects\submodule\root.py", line 339, in update
        keep_going=keep_going)
      File "C:\Program Files\Python36\lib\site-packages\git\objects\submodule\root.py", line 201, in update
        smr.fetch(progress=progress)
      File "C:\Program Files\Python36\lib\site-packages\git\remote.py", line 789, in fetch
        res = self._get_fetch_info_from_stderr(proc, progress)
      File "C:\Program Files\Python36\lib\site-packages\git\remote.py", line 675, in _get_fetch_info_from_stderr
        proc.wait(stderr=stderr_text)
      File "C:\Program Files\Python36\lib\site-packages\git\cmd.py", line 415, in wait
        raise GitCommandError(self.args, status, errstr)
    git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
      cmdline: git fetch --progress -v __new_origin__
      stderr: 'fatal: '../HelperModule.git' does not appear to be a git repository
    fatal: Could not read from remote repository.
    

    We are on a Gitlab instance where relative submodule URLs are a must have:

    If you are using GitLab 8.12+ and your submodule is on the same GitLab server, you must update your .gitmodules file to use relative URLs

  3. sfuller commented on Dec 30, 2018

    @sfuller
    sfuller
    on Dec 30, 2018
    More actions

    I was able to workaround this issue by manually resolving the relative path in the .gitmodules file. If you care about the .gitmodules file retaining the relative path url, you could easily just set the original url back to the .gitmodules file after operating on the repo with gitpython.

    for submodule in repo.submodules:
    
        # Hack around gitpython bug: https://github.com/gitpython-developers/GitPython/issues/730
        if submodule.url.startswith('..'):
            submodule_repo_name = submodule.url[3:]  # Strip off '../'
            repo_parent_url, _ = os.path.split(origin.url)
            actual_url = os.path.join(repo_parent_url, submodule_repo_name)
            with submodule.config_writer() as writer:
                writer.set('url', actual_url)
    
        print(f'Processing submodule {submodule.name}')
        submodule.update(init=True)
    Reacted by Bruceforce
  4. Bruceforce commented on Dec 31, 2018

    @Bruceforce
    Bruceforce
    on Dec 31, 2018
    More actions

    Another workaround I'm currently using is to use git directly as described in https://gitpython.readthedocs.io/en/stable/tutorial.html#using-git-directly

    for sm in repo.submodules:
          # Calling git directly for own submodules since using relative path is not working in gitpython
          # see https://github.com/gitpython-developers/GitPython/issues/730
          if sm.url[0:3] == '../':
              repo.git.submodule('init', sm.name)
              repo.git.submodule('update', sm.name)
          # For external submodules we can use the update function of gitpython
          else:
              sm.update()
    Reacted by Sam Fuller, sp-ricard-valverde and PhilippSelenium
  5. PhilLab
    added 2 commits that reference this issue on May 19, 2019

    Towards handling of relative submodule paths

    9965963

    Relative URLs for submodules

    04c9924
  6. david0
    added 3 commits that reference this issue on Jun 11, 2025

    fix updating submodules with relative urls

    This issue will close once commit 200b03b is merged into the 'main' branch.
    200b03b

    fix updating submodules with relative urls

    This issue will close once commit 76f3bf3 is merged into the 'main' branch.
    76f3bf3

    fix updating submodules with relative urls

    This issue will close once commit 1d80891 is merged into the 'main' branch.
    1d80891
  7. Byron
    closed this as completedin #2051on Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.