mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2026-07-26 18:17:30 +08:00
fix(git): handle divergent branches safely + datetime fallback
- Use --ff-only flag to detect non-fast-forward situations - Create backup branch before resetting divergent local branch - Reset to remote branch when fast-forward is not possible - Add timestamp_utils.py for Mac datetime module compatibility - Migrate all datetime usages to centralized utilities - Bump version to 4.0.3b5 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
3425fb7a14
commit
8e8b6ca724
@@ -12,9 +12,9 @@ import re
|
||||
import shutil
|
||||
import configparser
|
||||
import platform
|
||||
from datetime import datetime
|
||||
|
||||
import git
|
||||
from comfyui_manager.common.timestamp_utils import get_timestamp_for_path, get_backup_branch_name
|
||||
from git.remote import RemoteProgress
|
||||
from urllib.parse import urlparse
|
||||
from tqdm.auto import tqdm
|
||||
@@ -2000,7 +2000,15 @@ def git_repo_update_check_with(path, do_fetch=False, do_update=False, no_deps=Fa
|
||||
return False, True
|
||||
|
||||
try:
|
||||
remote.pull()
|
||||
try:
|
||||
repo.git.pull('--ff-only')
|
||||
except git.GitCommandError:
|
||||
backup_name = get_backup_branch_name(repo)
|
||||
repo.create_head(backup_name)
|
||||
logging.info(f"[ComfyUI-Manager] Cannot fast-forward. Backup created: {backup_name}")
|
||||
repo.git.reset('--hard', f'{remote_name}/{branch_name}')
|
||||
logging.info(f"[ComfyUI-Manager] Reset to {remote_name}/{branch_name}")
|
||||
|
||||
repo.git.submodule('update', '--init', '--recursive')
|
||||
new_commit_hash = repo.head.commit.hexsha
|
||||
|
||||
@@ -2169,9 +2177,17 @@ def git_pull(path):
|
||||
|
||||
current_branch = repo.active_branch
|
||||
remote_name = current_branch.tracking_branch().remote_name
|
||||
remote = repo.remote(name=remote_name)
|
||||
branch_name = current_branch.name
|
||||
|
||||
try:
|
||||
repo.git.pull('--ff-only')
|
||||
except git.GitCommandError:
|
||||
backup_name = get_backup_branch_name(repo)
|
||||
repo.create_head(backup_name)
|
||||
logging.info(f"[ComfyUI-Manager] Cannot fast-forward. Backup created: {backup_name}")
|
||||
repo.git.reset('--hard', f'{remote_name}/{branch_name}')
|
||||
logging.info(f"[ComfyUI-Manager] Reset to {remote_name}/{branch_name}")
|
||||
|
||||
remote.pull()
|
||||
repo.git.submodule('update', '--init', '--recursive')
|
||||
|
||||
repo.close()
|
||||
@@ -2681,9 +2697,7 @@ async def get_current_snapshot(custom_nodes_only = False):
|
||||
|
||||
async def save_snapshot_with_postfix(postfix, path=None, custom_nodes_only = False):
|
||||
if path is None:
|
||||
now = datetime.now()
|
||||
|
||||
date_time_format = now.strftime("%Y-%m-%d_%H-%M-%S")
|
||||
date_time_format = get_timestamp_for_path()
|
||||
file_name = f"{date_time_format}_{postfix}"
|
||||
|
||||
path = os.path.join(context.manager_snapshot_path, f"{file_name}.json")
|
||||
|
||||
@@ -20,10 +20,12 @@ import threading
|
||||
import traceback
|
||||
import urllib.request
|
||||
import uuid
|
||||
import time
|
||||
import zipfile
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Optional
|
||||
|
||||
from comfyui_manager.common.timestamp_utils import get_timestamp_for_filename, get_now
|
||||
|
||||
import folder_paths
|
||||
import latent_preview
|
||||
import nodes
|
||||
@@ -267,9 +269,9 @@ class TaskQueue:
|
||||
def _start_new_batch(self) -> None:
|
||||
"""Start a new batch session for tracking operations."""
|
||||
self.batch_id = (
|
||||
f"batch_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:8]}"
|
||||
f"batch_{get_timestamp_for_filename()}_{uuid.uuid4().hex[:8]}"
|
||||
)
|
||||
self.batch_start_time = datetime.now().isoformat()
|
||||
self.batch_start_time = get_now().isoformat()
|
||||
self.batch_state_before = self._capture_system_state()
|
||||
logging.debug("[ComfyUI-Manager] Started new batch: %s", self.batch_id)
|
||||
|
||||
@@ -300,7 +302,7 @@ class TaskQueue:
|
||||
MessageTaskStarted(
|
||||
ui_id=item.ui_id,
|
||||
kind=item.kind,
|
||||
timestamp=datetime.now(),
|
||||
timestamp=get_now(),
|
||||
state=self.get_current_state(),
|
||||
),
|
||||
client_id=item.client_id, # Send task started only to the client that requested it
|
||||
@@ -317,8 +319,7 @@ class TaskQueue:
|
||||
"""Mark task as completed and add to history"""
|
||||
|
||||
with self.mutex:
|
||||
now = datetime.now()
|
||||
timestamp = now.isoformat()
|
||||
now = get_now()
|
||||
|
||||
# Remove task from running_tasks using the task_index
|
||||
self.running_tasks.pop(task_index, None)
|
||||
@@ -383,7 +384,7 @@ class TaskQueue:
|
||||
result=result_msg,
|
||||
kind=item.kind,
|
||||
status=status,
|
||||
timestamp=datetime.fromisoformat(timestamp),
|
||||
timestamp=now,
|
||||
state=self.get_current_state(),
|
||||
),
|
||||
client_id=item.client_id, # Send completion only to the client that requested it
|
||||
@@ -494,7 +495,7 @@ class TaskQueue:
|
||||
)
|
||||
|
||||
try:
|
||||
end_time = datetime.now().isoformat()
|
||||
end_time = get_now().isoformat()
|
||||
state_after = self._capture_system_state()
|
||||
operations = self._extract_batch_operations()
|
||||
|
||||
@@ -562,7 +563,7 @@ class TaskQueue:
|
||||
"""Capture current ComfyUI system state for batch record."""
|
||||
logging.debug("[ComfyUI-Manager] Capturing system state for batch record")
|
||||
return ComfyUISystemState(
|
||||
snapshot_time=datetime.now().isoformat(),
|
||||
snapshot_time=get_now().isoformat(),
|
||||
comfyui_version=self._get_comfyui_version_info(),
|
||||
frontend_version=self._get_frontend_version(),
|
||||
python_version=platform.python_version(),
|
||||
@@ -789,8 +790,8 @@ class TaskQueue:
|
||||
to avoid disrupting normal operations.
|
||||
"""
|
||||
try:
|
||||
cutoff = datetime.now() - timedelta(days=16)
|
||||
cutoff_timestamp = cutoff.timestamp()
|
||||
# 16 days in seconds
|
||||
cutoff_timestamp = time.time() - (16 * 24 * 60 * 60)
|
||||
|
||||
pattern = os.path.join(context.manager_batch_history_path, "batch_*.json")
|
||||
removed_count = 0
|
||||
|
||||
Reference in New Issue
Block a user