Skip to content

Commit 6927b77

Browse files
Merge pull request #8 from 0niel/fix/git-commit-identity
Fix git identity setup
2 parents d90816c + 588c62a commit 6927b77

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

run.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,51 @@ def apply_source_patches():
100100
)
101101
logger.info("Applied patch {}, out={}", rel_path, out.stdout.strip())
102102
except subprocess.CalledProcessError as e:
103-
logger.error("Failed to apply patch {}: {}", rel_path, e.stderr.decode().strip())
103+
stderr = e.stderr
104+
if isinstance(stderr, bytes):
105+
stderr = stderr.decode(errors="replace")
106+
logger.error("Failed to apply patch {}: {}", rel_path, (stderr or "").strip())
107+
108+
109+
def ensure_git_identity(repo_dir: Path):
110+
def get_config(key: str) -> str:
111+
result = subprocess.run(
112+
["git", "config", "--get", key],
113+
cwd=str(repo_dir),
114+
capture_output=True,
115+
text=True
116+
)
117+
return (result.stdout or "").strip()
118+
119+
def set_config(key: str, value: str):
120+
subprocess.run(
121+
["git", "config", key, value],
122+
cwd=str(repo_dir),
123+
check=True
124+
)
125+
126+
name = get_config("user.name")
127+
email = get_config("user.email")
128+
129+
if not name:
130+
name = (
131+
os.getenv("GIT_AUTHOR_NAME")
132+
or os.getenv("GIT_COMMITTER_NAME")
133+
or os.getenv("USERNAME")
134+
or "Hytale Patcher"
135+
)
136+
set_config("user.name", name)
137+
logger.info("Set git user.name to {}", name)
138+
139+
if not email:
140+
email = (
141+
os.getenv("GIT_AUTHOR_EMAIL")
142+
or os.getenv("GIT_COMMITTER_EMAIL")
143+
or (f"{name.replace(' ', '').lower()}@local" if name else "")
144+
or "patcher@local"
145+
)
146+
set_config("user.email", email)
147+
logger.info("Set git user.email to {}", email)
104148

105149

106150
def make_source_patches():
@@ -294,7 +338,8 @@ def make_source_patches():
294338

295339
repo = Repository(str(Constants.PROJECT_DIR))
296340
repo.execute("init")
297-
repo.add_files([".gitignore"])
341+
ensure_git_identity(Constants.PROJECT_DIR)
342+
repo.add_files(['.gitignore'])
298343
repo.add_files(all_files=True)
299344
repo.commit("Initial decompilation")
300345
repo.execute("tag baseline")

0 commit comments

Comments
 (0)