Skip to content

Commit 4731afb

Browse files
committed
[WIP][GitRepository] Implement #git_transaction
All actions git write actions implement `with_worktree`, so this is a simple place to implement `git_transaction` and apply it safely. TODO: `GitRepository#worktree` probably doesn't need `#git_transaction` since it should only be called from `#with_worktree`, but want to confirm with others. This commit will be rebased once that is determined.
1 parent 436daa2 commit 4731afb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app/models/git_repository.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ def self_signed_cert_cb(_valid, _host)
7171
true
7272
end
7373

74+
# NOTE: Please make sure to use this whenever you implement a method that is
75+
# modifying the `.git` data (clone, fetch, checking, etc.) so that we can be
76+
# sure this happens safely between processes.
7477
def with_worktree
75-
handling_worktree_errors do
76-
yield worktree
78+
git_transaction do
79+
handling_worktree_errors do
80+
yield worktree
81+
end
7782
end
7883
end
7984

@@ -149,8 +154,10 @@ def refresh_tags
149154

150155
def worktree
151156
@worktree ||= begin
152-
clone_repo unless Dir.exist?(directory_name)
153-
fetch_worktree
157+
git_transaction do
158+
clone_repo unless Dir.exist?(directory_name)
159+
fetch_worktree
160+
end
154161
end
155162
end
156163

0 commit comments

Comments
 (0)