0

I have a repo including two submodules. I want to detect the changes in submodules.

For example, I have a repo called repo1 and there are two submodules in it called sub_repo1 and sub_repo2. I want to detect changes in these two submodules and merge it into repo1. I have tried the following code

from git import Repo
repo = Repo(repo1_path)
for submodule in repo.submodules():
    <I cannot find more reference>

I cannot find the reference about how to detect submodule changes.

I can use git diff in these submodules to find the remote changes.

My questions are:

  1. Can I detect changes in submodule?
  2. Can I get the listed result rather than a mass of string like git diff using GitPython (like a class called )?

Thanks a lot.

The reference I have checked are:

  1. Get changed files using gitpython
  2. GitPython check if git pull changed local files
  3. how to do a git diff of current commit with last commit using gitpython?
Elegant Lin
  • 25
  • 2
  • 10

1 Answers1

1

A list of git.diff.Diff objects representing the changes in the submodules of a repository at the path .git can be shown using:

from git import Repo

repo = Repo(".git")

for s in repo.submodules:
    print(s.module().index.diff(None))

The documentation here states that module() is the repository referenced by the submodule. The diff obtained in the example above is for changes between the index and the working copy. Further details about obtaining diff information can be found here.

pxul
  • 497
  • 1
  • 3
  • 13