GitPython
GitPython copied to clipboard
Fails to commit files one by one
I'm trying to add files one by one to my git repo (with custom git messages depending on some conditions) the problem is GitPython creates the commit but also adds some of these files to the staging area (and all the files are already committed).
When I have a single file to commit then I'm not facing any issues, this only surfaces with multiple files to commit.
Images
Code
add_file = repo.index.add
commit_file = repo.index.commit
....
....
for f in untracked_files:
is_file_private = False
solution_type = None
commit_emoji = None
commit_msg = None
with open(Path(repo.working_tree_dir).joinpath(f)) as target:
solution_type = target.readline().strip("#").split()[0]
if solution_type == 'PVT':
is_file_private = True
if not is_file_private:
count_untracked_files += 1
add_file([f])
.......
.......
commit_file("{} {}".format(commit_emoji, commit_msg))
I'm have created this workaround, for now, if anybody needs it
But If you invoke it from any other directory you will get an error
fatal: not a git repository (or any of the parent directories): .git
Code
from subprocess import call
....
....
commit_file = call
....
....
commit_file(["git", "commit", "-m", f"{commit_emoji} {commit_msg}"])