Evita manutenzione automatica Git durante aggiornamento Windows
This commit is contained in:
@@ -69,9 +69,11 @@ if errorlevel 1 goto failed
|
||||
|
||||
echo.
|
||||
echo Scaricamento di main da Gitea...
|
||||
git fetch origin refs/heads/main
|
||||
rem Avoid repacking/deleting old pack indexes during deployment on Windows.
|
||||
rem These settings apply only to this command, not to the repository config.
|
||||
git -c maintenance.auto=false -c gc.auto=0 fetch origin refs/heads/main
|
||||
if errorlevel 1 (
|
||||
echo ERRORE: scaricamento fallito. Verificare rete e credenziali Gitea.
|
||||
echo ERRORE: scaricamento fallito. Verificare rete, credenziali e accesso ai file .git.
|
||||
goto failed
|
||||
)
|
||||
set "TARGET="
|
||||
@@ -118,7 +120,7 @@ if errorlevel 1 (
|
||||
git switch main
|
||||
)
|
||||
if errorlevel 1 goto failed
|
||||
git merge --ff-only %TARGET%
|
||||
git -c maintenance.auto=false -c gc.auto=0 merge --ff-only %TARGET%
|
||||
if errorlevel 1 goto failed
|
||||
|
||||
echo.
|
||||
|
||||
@@ -70,3 +70,38 @@ patch SQL, configurazioni locali o aggiornamenti dei pacchetti Python. La copia
|
||||
locale db_connection.json non viene caricata da Gitea e rimane quella del reparto.
|
||||
|
||||
Il codice di uscita e' 0 per successo, 1 per errore, 2 per annullamento.
|
||||
|
||||
## Errore Unlink su .git/objects/pack/*.idx
|
||||
|
||||
Durante fetch Git puo' lanciare automaticamente manutenzione/ricompattazione.
|
||||
Su Windows questa puo' fallire quando un vecchio indice pack e' bloccato da un
|
||||
processo o non puo' essere eliminato per motivi di permessi. Il messaggio da solo
|
||||
non identifica chi blocca il file. Non cancellare manualmente file .idx o .pack.
|
||||
|
||||
Il BAT disabilita la manutenzione automatica SOLO per fetch e merge, tramite
|
||||
`git -c maintenance.auto=false -c gc.auto=0 ...`. Non modifica la configurazione
|
||||
permanente di Git e non arresta eventuali manutenzioni gia' in corso o pianificate.
|
||||
Non risolve permessi mancanti o blocchi che impediscono la normale scrittura Git.
|
||||
|
||||
Per recuperare il nuovo BAT mentre si dispone ancora di quello precedente, dopo
|
||||
aver terminato l'operazione Git precedente, dal prompt CMD:
|
||||
|
||||
```bat
|
||||
cd /d C:\flywms
|
||||
git -c maintenance.auto=false -c gc.auto=0 fetch origin refs/heads/main
|
||||
```
|
||||
|
||||
Solo se fetch ha successo, estrarre il BAT in una cartella esterna gia' esistente:
|
||||
|
||||
```bat
|
||||
git show FETCH_HEAD:aggiorna_monolista.bat > C:\tmp\aggiorna_monolista_nuovo.bat
|
||||
```
|
||||
|
||||
Solo se anche questo comando ha successo:
|
||||
|
||||
```bat
|
||||
C:\tmp\aggiorna_monolista_nuovo.bat C:\flywms C:\Python314\python.exe
|
||||
```
|
||||
|
||||
Questa procedura non modifica singolarmente il BAT tracciato nella cartella
|
||||
installata (che altrimenti risulterebbe modificato e bloccherebbe i controlli).
|
||||
|
||||
@@ -45,12 +45,15 @@ class DeployBatTests(unittest.TestCase):
|
||||
|
||||
def run_script(self, confirmation="S"):
|
||||
env = os.environ.copy()
|
||||
env.update(TEMP=str(self.base), TMP=str(self.base), PIP_NO_INDEX="1", PIP_DISABLE_PIP_VERSION_CHECK="1")
|
||||
env.update(TEMP=str(self.base), TMP=str(self.base), PIP_NO_INDEX="1", PIP_DISABLE_PIP_VERSION_CHECK="1",
|
||||
GIT_TRACE2_EVENT=str(self.base / "git-trace.jsonl"))
|
||||
command = f'""{self.script}" "{self.deploy}" "{sys.executable}""'
|
||||
return subprocess.run("cmd.exe /d /s /c " + command,
|
||||
input=confirmation + "\n\n", text=True, capture_output=True, env=env, timeout=60)
|
||||
|
||||
def test_success_preserves_config_and_saves_previous_commit(self):
|
||||
self.git("config", "maintenance.auto", "true", cwd=self.deploy)
|
||||
self.git("config", "gc.auto", "1", cwd=self.deploy)
|
||||
result = self.run_script()
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertIn("AGGIORNAMENTO COMPLETATO", result.stdout)
|
||||
@@ -58,6 +61,12 @@ class DeployBatTests(unittest.TestCase):
|
||||
self.assertEqual((self.deploy / "db_connection.json").read_text(), "LOCAL CONFIG")
|
||||
refs = self.git("for-each-ref", "--format=%(objectname)", "refs/warehouse-backups/", cwd=self.deploy)
|
||||
self.assertIn(self.before, refs)
|
||||
import json
|
||||
trace = [json.loads(line) for line in (self.base / "git-trace.jsonl").read_text(encoding="utf-8").splitlines()]
|
||||
children = [event.get("argv", []) for event in trace if event.get("event") == "child_start"]
|
||||
self.assertFalse(any("maintenance" in args or "gc" in args for args in children), children)
|
||||
self.assertEqual(self.git("config", "maintenance.auto", cwd=self.deploy).strip(), "true")
|
||||
self.assertEqual(self.git("config", "gc.auto", cwd=self.deploy).strip(), "1")
|
||||
|
||||
def test_dirty_checkout_is_not_overwritten(self):
|
||||
(self.deploy / "sample.txt").write_text("local", encoding="ascii")
|
||||
|
||||
Reference in New Issue
Block a user