5

これまでの私のコードは、次のように動作しています。subprocess.call() のものを取り除きたい

import git
from subprocess import call

repo = git.Repo(repo_path)
repo.remotes.origin.fetch(prune=True)
repo.head.reset(commit='origin/master', index=True, working_tree=True)

# I don't know how to do this using GitPython yet.
os.chdir(repo_path)
call(['git', 'submodule', 'update', '--init'])
4

2 に答える 2

17

私の短い答え: 便利でシンプルです。

完全な答えは次のとおりです。repo 変数があるとします。

repo = git.Repo(repo_path)

次に、次のようにします。

for submodule in repo.submodules:
    submodule.update(init=True)

submodule.module()そして、次のように、通常のリポジトリ( type git.Repo)で行うすべてのことをサブモジュールで行うことができます。

sub_repo = submodule.module()
sub_repo.git.checkout('devel')
sub_repo.git.remote('maybeorigin').fetch()

私はいくつかのプロジェクトを管理するために使用するgit porcelain よりも、自分の磁器でそのようなものを使用しています。


また、より直接的に行うには、call()orを使用する代わりに、次のようにsubprocessします。

repo = git.Repo(repo_path)
output = repo.git.submodule('update', '--init')
print(output)

メソッドは通常実行して得られる出力を返すため、印刷できますgit submodule update --init(明らかに、そのprint()部分は Python のバージョンに依存します)。

于 2015-06-04T12:48:51.923 に答える