Upload !archived!entry_with_update.py
Browse files
RuinedFooocus/!archived!entry_with_update.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
root = Path(__file__).resolve().parent
|
| 6 |
+
sys.path.append(str(root))
|
| 7 |
+
os.chdir(root)
|
| 8 |
+
|
| 9 |
+
offline = os.environ.get("RF_OFFLINE") == "1" or "--offline" in sys.argv
|
| 10 |
+
|
| 11 |
+
if not offline:
|
| 12 |
+
bupdated = False
|
| 13 |
+
try:
|
| 14 |
+
import pygit2
|
| 15 |
+
|
| 16 |
+
pygit2.option(pygit2.GIT_OPT_SET_OWNER_VALIDATION, 0)
|
| 17 |
+
|
| 18 |
+
repo_path = Path(__file__).resolve().parent
|
| 19 |
+
repo = pygit2.Repository(str(repo_path))
|
| 20 |
+
|
| 21 |
+
branch_name = repo.head.shorthand
|
| 22 |
+
|
| 23 |
+
remote_name = "origin"
|
| 24 |
+
remote = repo.remotes[remote_name]
|
| 25 |
+
|
| 26 |
+
remote.fetch()
|
| 27 |
+
|
| 28 |
+
local_branch_ref = f"refs/heads/{branch_name}"
|
| 29 |
+
local_branch = repo.lookup_reference(local_branch_ref)
|
| 30 |
+
|
| 31 |
+
remote_reference = f"refs/remotes/{remote_name}/{branch_name}"
|
| 32 |
+
remote_commit = repo.revparse_single(remote_reference)
|
| 33 |
+
|
| 34 |
+
merge_result, _ = repo.merge_analysis(remote_commit.id)
|
| 35 |
+
|
| 36 |
+
if merge_result & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE:
|
| 37 |
+
print("You have the latest version")
|
| 38 |
+
elif merge_result & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD:
|
| 39 |
+
local_branch.set_target(remote_commit.id)
|
| 40 |
+
repo.head.set_target(remote_commit.id)
|
| 41 |
+
repo.checkout_tree(repo.get(remote_commit.id))
|
| 42 |
+
repo.reset(local_branch.target, pygit2.GIT_RESET_HARD)
|
| 43 |
+
print("Updating Files")
|
| 44 |
+
bupdated = True
|
| 45 |
+
elif merge_result & pygit2.GIT_MERGE_ANALYSIS_NORMAL:
|
| 46 |
+
print("Update failed, Did you modify any files?")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print("Update failed...")
|
| 49 |
+
print(str(e))
|
| 50 |
+
if bupdated:
|
| 51 |
+
print("Update succeeded!!")
|
| 52 |
+
else:
|
| 53 |
+
print("Offline mode. No update.")
|
| 54 |
+
from launch import *
|