diff --git a/.claude/settings.local.json b/.claude/settings.local.json index dbc113f..61ba69f 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -4,7 +4,8 @@ "Bash(python git_updater.py)", "Bash(pip show:*)", "Bash(pip install:*)", - "Bash(pyinstaller --onefile --windowed --name \"GitUpdateChecker\" git_updater.py)" + "Bash(pyinstaller --onefile --windowed --name \"GitUpdateChecker\" git_updater.py)", + "Bash(pyinstaller --onefile --console --name \"GitUpdateChecker\" --icon=NONE git_updater.py)" ] } } diff --git a/GitUpdateChecker.exe b/GitUpdateChecker.exe index 46df93b..46203fe 100644 Binary files a/GitUpdateChecker.exe and b/GitUpdateChecker.exe differ diff --git a/git_updater.py b/git_updater.py index 7e0f38c..f443369 100644 --- a/git_updater.py +++ b/git_updater.py @@ -135,6 +135,12 @@ def check_self_update(): cwd=exe_dir, ) count = len(log_out.splitlines()) if code == 0 and log_out else 0 + + if count == 0: + # Hashes differents mais aucun commit a tirer (local en avance) -> pas de MAJ + log.info("Auto-update: hashes differents mais 0 commit a tirer, skip") + return False, "" + info = f"{count} commit(s) en retard sur origin/{branch}" log.info(f"Auto-update: MAJ disponible - {info}") return True, info @@ -170,23 +176,30 @@ def do_self_update(): log.error(f"Auto-update: impossible de renommer l'exe: {e}") return False, f"Impossible de renommer l'exe: {e}" - # Restaurer les fichiers locaux modifiés puis pull - run_git(["checkout", "--", "."], cwd=exe_dir) - code, _, err = run_git(["pull", "origin", branch], cwd=exe_dir) + # Pull avec fast-forward only (evite de toucher config.ini inutilement) + code, _, err = run_git(["pull", "--ff-only", "origin", branch], cwd=exe_dir) if code == 0: log.info("Auto-update: pull OK") return True, "Mise a jour reussie !\nLe programme va redemarrer." - else: - # En cas d'échec, restaurer l'ancien exe - if is_frozen and exe_old_path and exe_old_path.exists(): - try: - exe_old_path.rename(Path(sys.executable)) - log.info("Auto-update: exe restaure apres echec") - except OSError: - pass - log.error(f"Auto-update: pull echoue: {err}") - return False, f"Erreur pull: {err}" + + # Si ff-only echoue (modifications locales), tenter reset hard sur origin + log.warning(f"Auto-update: pull --ff-only echoue ({err}), tentative reset...") + run_git(["reset", "--hard", f"origin/{branch}"], cwd=exe_dir) + code2, _, err2 = run_git(["pull", "--ff-only", "origin", branch], cwd=exe_dir) + if code2 == 0: + log.info("Auto-update: reset + pull OK") + return True, "Mise a jour reussie !\nLe programme va redemarrer." + + # Echec definitif, restaurer l'ancien exe + if is_frozen and exe_old_path and exe_old_path.exists(): + try: + exe_old_path.rename(Path(sys.executable)) + log.info("Auto-update: exe restaure apres echec") + except OSError: + pass + log.error(f"Auto-update: pull echoue: {err2}") + return False, f"Erreur pull: {err2}" def relaunch_program():