| package git |
| |
| import ( |
| "sync" |
| ) |
| |
| // GitMutex provides thread-safe access to Git operations |
| // Since Git is not thread-safe, we need to serialize all Git operations |
| // across all agents to prevent repository corruption and race conditions |
| type GitMutex struct { |
| mu sync.Mutex |
| } |
| |
| // NewGitMutex creates a new GitMutex instance |
| func NewGitMutex() *GitMutex { |
| return &GitMutex{} |
| } |
| |
| // Lock acquires the Git operation lock |
| // This ensures only one agent can perform Git operations at a time |
| func (gm *GitMutex) Lock() { |
| gm.mu.Lock() |
| } |
| |
| // Unlock releases the Git operation lock |
| func (gm *GitMutex) Unlock() { |
| gm.mu.Unlock() |
| } |
| |
| // WithLock executes a function while holding the Git lock |
| // This is a convenience method to ensure proper lock/unlock pattern |
| func (gm *GitMutex) WithLock(fn func() error) error { |
| gm.Lock() |
| defer gm.Unlock() |
| return fn() |
| } |
| |
| // Global Git mutex instance - shared across all agents |
| // This ensures no concurrent Git operations across the entire application |
| var GlobalGitMutex = NewGitMutex() |