How to push files modified by a pre-push hook on Git?

381 Views Asked by At

I have a Python script as a pre-push hook modyfing files inside my repo. Is there any possibility to immediately push those modified files as part of the same push?

Here is the code:

#!/usr/bin/env python

def sendUnpackedAsset():
    """Scan all .hdas available in the repo and unpack them."""

    hdas = os.listdir(
        f"{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/otls"
    )

    for count, hda in enumerate(hdas, start=1):
        if hda.endswith(".hda") or hda.endswith(".otl"):

            print(f">>> Unpacking {count} digital asset(s)...")

            unpackAsset(
                unpacked_dir_name=f"{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/otls/{os.path.splitext(hda)[0]}",
                source_hda_file=f"{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/otls/{hda}",
            )

            if os.path.isfile(hda):
                print(f">>> Removing {count} digital asset(s)...")
                os.remove(hda)

It is modyfing binary files .hda or .otl contained in the repo, unpacking them to .txt files, and then removing the binary, leaving only the freshly created .txt files in the repo. Unfortunately, I need to push a second times to have those changes applied.

1

There are 1 best solutions below

1
On

I think you'd have to git add any modified files and create a second commit, then push it all.