@@ -354,12 +354,14 @@ def build_lock_payload(
354354 config : dict [str , Any ],
355355 * ,
356356 engine_id : str ,
357+ python_version : str | None = None ,
357358) -> dict [str , Any ]:
358359 return _build_lock_payload (
359360 workspace ,
360361 config ,
361362 engine_id = engine_id ,
362363 engine_version = engine_version (engine_id ),
364+ python_version = python_version ,
363365 )
364366
365367
@@ -407,15 +409,22 @@ def engine_config_from_lock(lock_payload: dict[str, Any]) -> dict[str, Any]:
407409
408410
409411def ensure_correct_git_commit (workspace : Path , lock_payload : dict [str , Any ]) -> bool :
410- """Vérifie si le commit Git actuel correspond à celui du verrou."""
411- locked_commit = ((lock_payload .get ("project" ) or {}).get ("git_commit" ))
412- if not locked_commit :
412+ """Vérifie si le commit et la branche Git actuels correspondent à ceux du verrou."""
413+ project = lock_payload .get ("project" ) or {}
414+ locked_commit = project .get ("git_commit" )
415+ locked_branch = project .get ("git_branch" )
416+
417+ if not locked_commit and not locked_branch :
413418 return True
414419
415- from Core .Locking import get_git_commit_hash
420+ from Core .Locking import get_git_commit_hash , get_git_branch
416421 current_commit = get_git_commit_hash (workspace )
422+ current_branch = get_git_branch (workspace )
423+
424+ commit_match = (not locked_commit ) or (current_commit == locked_commit )
425+ branch_match = (not locked_branch ) or (current_branch == locked_branch )
417426
418- if not current_commit or current_commit == locked_commit :
427+ if commit_match and branch_match :
419428 return True
420429
421430 from .output import warn , info , error , success
@@ -425,26 +434,46 @@ def ensure_correct_git_commit(workspace: Path, lock_payload: dict[str, Any]) ->
425434 is_linux = platform .system ().lower () == "linux"
426435
427436 warn (f"Mismatch Git détecté." )
428- info (f" - Verrou : { locked_commit [:8 ]} " )
429- info (f" - Actuel : { current_commit [:8 ]} " )
437+ if not branch_match :
438+ info (f" - Branche Verrou : { locked_branch } " )
439+ info (f" - Branche Actuelle : { current_branch } " )
440+ if not commit_match :
441+ info (f" - Commit Verrou : { locked_commit [:8 ] if locked_commit else 'N/A' } " )
442+ info (f" - Commit Actuel : { current_commit [:8 ] if current_commit else 'N/A' } " )
430443
431444 if is_linux :
432445 try :
433446 import click
434- if click .confirm (f"Effectuer un 'git checkout { locked_commit [:8 ]} ' automatique ?" , default = True ):
435- info (f"Alignement Git en cours..." )
436- subprocess .run (["git" , "checkout" , locked_commit ], cwd = str (workspace ), check = True )
447+ if not branch_match and locked_branch :
448+ if click .confirm (f"Effectuer un 'git checkout { locked_branch } ' automatique ?" , default = True ):
449+ info (f"Changement de branche en cours..." )
450+ subprocess .run (["git" , "checkout" , locked_branch ], cwd = str (workspace ), check = True )
451+ # Re-verify commit after branch change
452+ current_commit = get_git_commit_hash (workspace )
453+ commit_match = (not locked_commit ) or (current_commit == locked_commit )
454+
455+ if not commit_match and locked_commit :
456+ if click .confirm (f"Effectuer un 'git checkout { locked_commit [:8 ]} ' automatique ?" , default = True ):
457+ info (f"Alignement du commit en cours..." )
458+ subprocess .run (["git" , "checkout" , locked_commit ], cwd = str (workspace ), check = True )
459+ success ("Workspace aligné." )
460+ return True
461+
462+ if commit_match and branch_match :
437463 success ("Workspace aligné." )
438464 return True
439465 else :
440466 warn ("Build avec mismatch (non recommandé)." )
441467 return True
442468 except Exception as e :
443- error (f"Échec checkout : { e } " )
469+ error (f"Échec alignement Git : { e } " )
444470 return False
445471 else :
446- warn ("Checkout automatique non supporté sur cette plateforme." )
447- info (f"Action manuelle requise : git checkout { locked_commit } " )
472+ warn ("Alignement automatique non supporté sur cette plateforme." )
473+ if not branch_match and locked_branch :
474+ info (f"Action manuelle requise : git checkout { locked_branch } " )
475+ if not commit_match and locked_commit :
476+ info (f"Action manuelle requise : git checkout { locked_commit } " )
448477 try :
449478 import click
450479 return click .confirm ("Continuer quand même ?" , default = False )
0 commit comments