Skip to content

Fails to commit files one by one #913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
NikSWE opened this issue Aug 24, 2019 · 1 comment
Open

Fails to commit files one by one #913

NikSWE opened this issue Aug 24, 2019 · 1 comment

Comments

@NikSWE
Copy link

NikSWE commented Aug 24, 2019

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

Screen Shot 2019-08-24 at 1 35 35 PM
Screen Shot 2019-08-24 at 1 35 52 PM
Screen Shot 2019-08-24 at 1 35 59 PM

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))
@NikSWE
Copy link
Author

NikSWE commented Aug 24, 2019

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}"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant