Created
March 7, 2023 01:17
-
-
Save mahelbir/75e4ccb2f0979897444edb05eb7fa8b2 to your computer and use it in GitHub Desktop.
Python script to zip changed files with .git (differences between working directory and staging area)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import os | |
import zipfile | |
import sys | |
from datetime import datetime | |
out = subprocess.check_output(["git", "diff", "--name-only", "--diff-filter=d"]).decode().splitlines() | |
out2 = subprocess.check_output(["git", "ls-files", "--others", "--exclude-standard"]).decode().splitlines() | |
if len(out) > 0 or len(out2) > 0: | |
if ".gitignore" in out: | |
out.remove(".gitignore") | |
if ".gitignore" in out2: | |
out2.remove(".gitignore") | |
if sys.argv[0] in out: | |
out.remove(sys.argv[0]) | |
if sys.argv[0] in out2: | |
out2.remove(sys.argv[0]) | |
zipName = "patch-" + datetime.now().strftime("%Y%m%d%H%M") + ".zip" | |
with zipfile.ZipFile(zipName, "w") as zip: | |
for line in out: | |
if os.path.exists(line): | |
zip.write(line) | |
for line in out2: | |
if os.path.exists(line): | |
zip.write(line) | |
print("New patch:", zipName) | |
else: | |
print("No patch!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
py PATCH.py
OR
Usage:
python PATCH.py
OR
Usage:
python3 PATCH.py