-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import sys | ||
import os | ||
import subprocess | ||
|
||
def usage(): | ||
print("Usage: {} [--check] <patch_file_path>".format(sys.argv[0])) | ||
sys.exit(1) | ||
|
||
def main(): | ||
# Check if the correct number of arguments is provided | ||
if len(sys.argv) < 2 or len(sys.argv) > 3: | ||
usage() | ||
|
||
# Initialize variables | ||
check_flag = "" | ||
patch_file = "" | ||
|
||
# Parse arguments | ||
if len(sys.argv) == 3: | ||
if sys.argv[1] == "--check": | ||
check_flag = "--check" | ||
patch_file = sys.argv[2] | ||
else: | ||
usage() | ||
else: | ||
patch_file = sys.argv[1] | ||
|
||
# Check if the patch file exists | ||
if not os.path.isfile(patch_file): | ||
print(f"Error: Patch file '{patch_file}' does not exist.") | ||
sys.exit(1) | ||
|
||
# Apply the patch | ||
try: | ||
command = ["git", "apply", "--3way"] | ||
if check_flag: | ||
command.append(check_flag) | ||
command.append(patch_file) | ||
subprocess.run(command, check=True) | ||
print("Patch applied successfully!") | ||
except subprocess.CalledProcessError: | ||
print("Failed to apply patch.") | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
main() |