Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
## Unreleased
### Added
- GitManager.fetch() cooldown to avoid redundant remote fetches, controlled by GIT_FETCH_COOLDOWN env var (default 30s)
### Fixed
- ephemeral git context push rejection when concurrent processes push to the same branch - pull before push to integrate remote changes


## 1.2.0
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Unreleased:
added:
- "GitManager.fetch() cooldown to avoid redundant remote fetches, controlled by GIT_FETCH_COOLDOWN env var (default 30s)"
fixed: []
fixed:
- ephemeral git context push rejection when concurrent processes push to the same branch - pull before push to integrate remote changes
changed: []
deprecated: []
removed: []
Expand Down
10 changes: 9 additions & 1 deletion src/ctl/util/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ def fetch(self, prune: bool = True, force: bool = False):
try:
cooldown = int(os.environ.get("GIT_FETCH_COOLDOWN", 30))
except (ValueError, TypeError):
self.log.error(f"Invalid GIT_FETCH_COOLDOWN value: {os.environ.get('GIT_FETCH_COOLDOWN')!r}, using default 30s")
self.log.error(
f"Invalid GIT_FETCH_COOLDOWN value: {os.environ.get('GIT_FETCH_COOLDOWN')!r}, using default 30s"
)
cooldown = 30

if not force and cooldown > 0:
Expand Down Expand Up @@ -1172,6 +1174,12 @@ def finalize(self, exc_type, exc_val, exc_tb):
self.git_manager.changed_files(self.state.files_to_add)
)
self.git_manager.commit(self.state.commit_message)
# Pull to integrate any remote changes before pushing,
# avoiding rejection when concurrent processes have
# pushed to the same branch
# If this fails due to conflicts, push would have also failed.
if not self.state.force_push:
self.git_manager.pull()
# Attempt to push
self.git_manager.push(force=self.state.force_push)

Expand Down
Loading