File tree 9 files changed +88
-0
lines changed
9 files changed +88
-0
lines changed Original file line number Diff line number Diff line change @@ -384,6 +384,22 @@ auto-update() {
384
384
unset HOMEBREW_AUTO_UPDATE_CASK_TAP
385
385
}
386
386
387
+ # Only `brew update-if-needed` should be handled here.
388
+ # We want it as fast as possible but it needs auto-update() defined above.
389
+ # HOMEBREW_LIBRARY set by bin/brew
390
+ # shellcheck disable=SC2154
391
+ # doesn't need a default case as other arguments handled elsewhere.
392
+ # shellcheck disable=SC2249
393
+ # Don't need to pass through any arguments.
394
+ # shellcheck disable=SC2119
395
+ case " $@ " in
396
+ update-if-needed)
397
+ source " ${HOMEBREW_LIBRARY} /Homebrew/cmd/update-if-needed.sh"
398
+ homebrew-update-if-needed
399
+ exit 0
400
+ ;;
401
+ esac
402
+
387
403
# ####
388
404
# #### Setup output so e.g. odie looks as nice as possible.
389
405
# ####
Original file line number Diff line number Diff line change
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "abstract_command"
5
+ require "shell_command"
6
+
7
+ module Homebrew
8
+ module Cmd
9
+ class UpdateIfNeeded < AbstractCommand
10
+ include ShellCommand
11
+
12
+ cmd_args do
13
+ description <<~EOS
14
+ Runs `brew update --auto-update` only if needed.
15
+ This is a good replacement for `brew update` in scripts where you want
16
+ the no-op case to be both possible and really fast.
17
+ EOS
18
+
19
+ named_args :none
20
+ end
21
+ end
22
+ end
23
+ end
Original file line number Diff line number Diff line change
1
+ # Documentation defined in Library/Homebrew/cmd/update-if-needed.rb
2
+
3
+ homebrew-update-if-needed () {
4
+ export HOMEBREW_AUTO_UPDATE_COMMAND=" 1"
5
+ auto-update " $@ "
6
+ }
Original file line number Diff line number Diff line change @@ -2798,6 +2798,22 @@ _brew_update() {
2798
2798
esac
2799
2799
}
2800
2800
2801
+ _brew_update_if_needed() {
2802
+ local cur="${COMP_WORDS[COMP_CWORD]}"
2803
+ case "${cur}" in
2804
+ -*)
2805
+ __brewcomp "
2806
+ --debug
2807
+ --help
2808
+ --quiet
2809
+ --verbose
2810
+ "
2811
+ return
2812
+ ;;
2813
+ *) ;;
2814
+ esac
2815
+ }
2816
+
2801
2817
_brew_update_license_data() {
2802
2818
local cur="${COMP_WORDS[COMP_CWORD]}"
2803
2819
case "${cur}" in
@@ -3214,6 +3230,7 @@ _brew() {
3214
3230
untap) _brew_untap ;;
3215
3231
up) _brew_up ;;
3216
3232
update) _brew_update ;;
3233
+ update-if-needed) _brew_update_if_needed ;;
3217
3234
update-license-data) _brew_update_license_data ;;
3218
3235
update-maintainers) _brew_update_maintainers ;;
3219
3236
update-python-resources) _brew_update_python_resources ;;
Original file line number Diff line number Diff line change @@ -1800,6 +1800,13 @@ __fish_brew_complete_arg 'update' -l quiet -d 'Make some output more quiet'
1800
1800
__fish_brew_complete_arg ' update' -l verbose -d ' Print the directories checked and `git` operations performed'
1801
1801
1802
1802
1803
+ __fish_brew_complete_cmd ' update-if-needed' ' Runs `brew update --auto-update` only if needed'
1804
+ __fish_brew_complete_arg ' update-if-needed' -l debug -d ' Display any debugging information'
1805
+ __fish_brew_complete_arg ' update-if-needed' -l help -d ' Show this message'
1806
+ __fish_brew_complete_arg ' update-if-needed' -l quiet -d ' Make some output more quiet'
1807
+ __fish_brew_complete_arg ' update-if-needed' -l verbose -d ' Make some output more verbose'
1808
+
1809
+
1803
1810
__fish_brew_complete_cmd ' update-license-data' ' Update SPDX license data in the Homebrew repository'
1804
1811
__fish_brew_complete_arg ' update-license-data' -l debug -d ' Display any debugging information'
1805
1812
__fish_brew_complete_arg ' update-license-data' -l help -d ' Show this message'
Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ unpin
114
114
untap
115
115
up
116
116
update
117
+ update-if-needed
117
118
update-license-data
118
119
update-maintainers
119
120
update-python-resources
Original file line number Diff line number Diff line change @@ -232,6 +232,7 @@ __brew_internal_commands() {
232
232
'unpin:Unpin formula, allowing them to be upgraded by `brew upgrade` formula'
233
233
'untap:Remove a tapped formula repository'
234
234
'update:Fetch the newest version of Homebrew and all formulae from GitHub using `git`(1) and perform any necessary migrations'
235
+ 'update-if-needed:Runs `brew update --auto-update` only if needed'
235
236
'update-license-data:Update SPDX license data in the Homebrew repository'
236
237
'update-maintainers:Update the list of maintainers in the `Homebrew/brew` README'
237
238
'update-python-resources:Update versions for PyPI resource blocks in formula'
@@ -2223,6 +2224,15 @@ _brew_update() {
2223
2224
'--verbose[Print the directories checked and `git` operations performed]'
2224
2225
}
2225
2226
2227
+ # brew update-if-needed
2228
+ _brew_update_if_needed() {
2229
+ _arguments \
2230
+ '--debug[Display any debugging information]' \
2231
+ '--help[Show this message]' \
2232
+ '--quiet[Make some output more quiet]' \
2233
+ '--verbose[Make some output more verbose]'
2234
+ }
2235
+
2226
2236
# brew update-license-data
2227
2237
_brew_update_license_data() {
2228
2238
_arguments \
Original file line number Diff line number Diff line change @@ -1610,6 +1610,12 @@ and perform any necessary migrations.
1610
1610
1611
1611
: Display a trace of all shell commands as they are executed.
1612
1612
1613
+ ### ` update-if-needed `
1614
+
1615
+ Runs ` brew update --auto-update ` only if needed. This is a good replacement for
1616
+ ` brew update ` in scripts where you want the no-op case to be both possible and
1617
+ really fast.
1618
+
1613
1619
### ` update-reset ` \[ * ` repository ` * ...\]
1614
1620
1615
1621
Fetch and reset Homebrew and all tap repositories (or any specified
Original file line number Diff line number Diff line change @@ -1005,6 +1005,8 @@ Print the directories checked and \fBgit\fP operations performed\.
1005
1005
.TP
1006
1006
\fB \- d \fP , \fB \-\- debug \fP
1007
1007
Display a trace of all shell commands as they are executed\.
1008
+ .SS "\fB update \- if \- needed \fP "
1009
+ Runs \fB brew update \-\- auto \- update \fP only if needed\. This is a good replacement for \fB brew update \fP in scripts where you want the no\- op case to be both possible and really fast\.
1008
1010
.SS "\fB update \- reset \fP \fR [\fI repository \fP \.\.\. ]"
1009
1011
Fetch and reset Homebrew and all tap repositories (or any specified \fI repository \fP ) using \fB git \fP (1) to their latest \fB origin/HEAD \fP \& \.
1010
1012
.P
You can’t perform that action at this time.
0 commit comments