blob: 21bc25fd51f7d34c9ac3e43c5ebb142801319ae9 [file] [log] [blame]
user5a7d60d2025-07-27 21:22:04 +04001package git
2
3import (
4 "sync"
5)
6
7// GitMutex provides thread-safe access to Git operations
8// Since Git is not thread-safe, we need to serialize all Git operations
9// across all agents to prevent repository corruption and race conditions
10type GitMutex struct {
11 mu sync.Mutex
12}
13
14// NewGitMutex creates a new GitMutex instance
15func NewGitMutex() *GitMutex {
16 return &GitMutex{}
17}
18
19// Lock acquires the Git operation lock
20// This ensures only one agent can perform Git operations at a time
21func (gm *GitMutex) Lock() {
22 gm.mu.Lock()
23}
24
25// Unlock releases the Git operation lock
26func (gm *GitMutex) Unlock() {
27 gm.mu.Unlock()
28}
29
30// WithLock executes a function while holding the Git lock
31// This is a convenience method to ensure proper lock/unlock pattern
32func (gm *GitMutex) WithLock(fn func() error) error {
33 gm.Lock()
34 defer gm.Unlock()
35 return fn()
36}
37
38// Global Git mutex instance - shared across all agents
39// This ensures no concurrent Git operations across the entire application
40var GlobalGitMutex = NewGitMutex()