Home > database >  empty commit with Repo.commit()
empty commit with Repo.commit()

Time:01-03

I'm trying to do something like repo.git.commit('-m', 'test commit', author='[email protected]') but instead of the author, I want to pass the --allow-empty to send a dummy commit to the repo. but the repo.git.commit() complains about the number of arguments I'm trying to pass. This is what I have so far:

from git import Repo
import os
from dotenv import load_dotenv

load_dotenv()

full_local_path = os.getenv('full_local_path')
username = os.getenv('username')
password = os.getenv('password')

remote = f"https://{username}:{password}@github.com:myRepo/myRepo.git"
Repo.clone_from('[email protected]:myRepo/myRepo.git', full_local_path)
Repo.git.commit('-m', 'empty commit', author='xxxxxxxxx')`

CodePudding user response:

You're ignoring the return value from Repo.clone_from, which is the Repo object on which you'll operate in subsequent commands. You want something like:

>>> from git import Repo
>>> r = Repo.clone_from('https://github.com/octocat/Hello-World', 'hello-world')
>>> r.git.commit('-m', 'empty commit', '--allow-empty')
'[master 8d7508e] empty commit'
  • Related