mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-06-15 09:08:27 +00:00
feat(updater): add cooldown option to delay applying updates (#13813)
Introduces a new `zstyle ':omz:update' cooldown <days>` setting that limits the updater to only apply commits that are at least N days old. Defaults to 0 (current behavior — always pull latest). When cooldown is set, the updater fetches the remote branch and finds the most recent commit whose committer timestamp is at least N days old, then applies it via `git merge --ff-only`. If the local copy is already at or past the cooldown ref, nothing changes. - tools/upgrade.sh: reads cooldown zstyle, replaces git pull with fetch + merge --ff-only when cooldown > 0 - README.md: documents the new setting under "Getting Updates" - templates/zshrc.zsh-template: adds commented-out cooldown example alongside frequency, with rephrased comments to clarify how the two work together
This commit is contained in:
@@ -231,6 +231,10 @@ local ret=0
|
||||
remote=${"$(git config --local oh-my-zsh.remote)":-origin}
|
||||
branch=${"$(git config --local oh-my-zsh.branch)":-master}
|
||||
|
||||
# cooldown: minimum age (in days) of commits to apply
|
||||
local cooldown_days
|
||||
zstyle -s ':omz:update' cooldown cooldown_days || cooldown_days=0
|
||||
|
||||
# repository state
|
||||
last_head=$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD)
|
||||
# checkout update branch
|
||||
@@ -242,7 +246,20 @@ last_commit=$(git rev-parse "$branch")
|
||||
if [[ $verbose_mode != silent ]]; then
|
||||
printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
|
||||
fi
|
||||
if LANG= git pull --quiet --rebase $remote $branch; then
|
||||
if {
|
||||
if (( cooldown_days > 0 )); then
|
||||
zmodload zsh/datetime
|
||||
local cutoff_epoch cooldown_ref
|
||||
cutoff_epoch=$(( EPOCHSECONDS - cooldown_days * 86400 ))
|
||||
LANG= git fetch --quiet $remote $branch && {
|
||||
cooldown_ref=$(git log --format="%H %ct" "$remote/$branch" \
|
||||
| awk -v c="$cutoff_epoch" '$2 <= c { print $1; exit }')
|
||||
[[ -z "$cooldown_ref" ]] || LANG= git merge --ff-only --quiet "$cooldown_ref"
|
||||
}
|
||||
else
|
||||
LANG= git pull --quiet --rebase $remote $branch
|
||||
fi
|
||||
}; then
|
||||
# Check if it was really updated or not
|
||||
if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
|
||||
message="Oh My Zsh is already at the latest version."
|
||||
|
||||
Reference in New Issue
Block a user