Skip to content

Don't commit if this would be an empty commit #1056

@mhajder

Description

@mhajder

Hi,
I have no idea how to write a functions without committing and sending code, if there are no changes and it's an empty commit.

from git import Repo, Actor

repo = Repo(full_path)
assert not repo.bare

origin = repo.remote('origin')
assert origin.exists()
assert origin == repo.remotes.origin == repo.remotes['origin']

origin.pull()
repo.git.add(f'{full_path}/file_list.txt')
repo.git.add(f'{full_path}/files/')

repo.index.commit(f'Time now: {time_now}')
origin.push()

Currently, after running such code, a commit is created with no changes to the files. I can't find any function that checks for any changes before commit after adding files. I don't mean changes to all code and to all files in the main .git folder, but changes to one file and one folder with many files.

I am also looking for a solution other than using untracked_files in a loop looking to see if my needed files are there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions