X Tutup
Skip to content

Commit 69b9aa3

Browse files
committed
Merge remote-tracking branch 'origin' into api-cache
2 parents 162a1b2 + 00cb921 commit 69b9aa3

40 files changed

+1515
-95
lines changed

cmd/gh/main.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,19 @@ func main() {
163163

164164
newRelease := <-updateMessageChan
165165
if newRelease != nil {
166-
ghExe, _ := os.Executable()
166+
isHomebrew := false
167+
if ghExe, err := os.Executable(); err == nil {
168+
isHomebrew = isUnderHomebrew(ghExe)
169+
}
170+
if isHomebrew && isRecentRelease(newRelease.PublishedAt) {
171+
// do not notify Homebrew users before the version bump had a chance to get merged into homebrew-core
172+
return
173+
}
167174
fmt.Fprintf(stderr, "\n\n%s %s → %s\n",
168175
ansi.Color("A new release of gh is available:", "yellow"),
169176
ansi.Color(buildVersion, "cyan"),
170177
ansi.Color(newRelease.Version, "cyan"))
171-
if suggestBrewUpgrade(newRelease, ghExe) {
178+
if isHomebrew {
172179
fmt.Fprintf(stderr, "To upgrade, run: %s\n", "brew update && brew upgrade gh")
173180
}
174181
fmt.Fprintf(stderr, "%s\n\n",
@@ -265,13 +272,12 @@ func apiVerboseLog() api.ClientOption {
265272
return api.VerboseLog(colorable.NewColorable(os.Stderr), logTraffic, colorize)
266273
}
267274

268-
// Suggest to `brew upgrade gh` only if gh was found under homebrew prefix and when the release was
269-
// published over 24h ago, allowing homebrew-core ample time to merge the formula bump.
270-
func suggestBrewUpgrade(rel *update.ReleaseInfo, ghBinary string) bool {
271-
if rel.PublishedAt.IsZero() || time.Since(rel.PublishedAt) < time.Duration(time.Hour*24) {
272-
return false
273-
}
275+
func isRecentRelease(publishedAt time.Time) bool {
276+
return !publishedAt.IsZero() && time.Since(publishedAt) < time.Hour*24
277+
}
274278

279+
// Check whether the gh binary was found under the Homebrew prefix
280+
func isUnderHomebrew(ghBinary string) bool {
275281
brewExe, err := safeexec.LookPath("brew")
276282
if err != nil {
277283
return false

git/fixtures/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.git/COMMIT_EDITMSG

git/fixtures/simple.git/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/main

git/fixtures/simple.git/config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
;bare = true
5+
ignorecase = true
6+
precomposeunicode = true
7+
[user]
8+
name = Mona the Cat
9+
email = monalisa@github.com

git/fixtures/simple.git/index

65 Bytes
Binary file not shown.

git/fixtures/simple.git/logs/HEAD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0000000000000000000000000000000000000000 d1e0abfb7d158ed544a202a6958c62d4fc22e12f Mona the Cat <monalisa@github.com> 1614174263 +0100 commit (initial): Initial commit
2+
d1e0abfb7d158ed544a202a6958c62d4fc22e12f 6f1a2405cace1633d89a79c74c65f22fe78f9659 Mona the Cat <monalisa@github.com> 1614174275 +0100 commit: Second commit
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0000000000000000000000000000000000000000 d1e0abfb7d158ed544a202a6958c62d4fc22e12f Mona the Cat <monalisa@github.com> 1614174263 +0100 commit (initial): Initial commit
2+
d1e0abfb7d158ed544a202a6958c62d4fc22e12f 6f1a2405cace1633d89a79c74c65f22fe78f9659 Mona the Cat <monalisa@github.com> 1614174275 +0100 commit: Second commit
Binary file not shown.
Binary file not shown.

git/fixtures/simple.git/objects/d1/e0abfb7d158ed544a202a6958c62d4fc22e12f

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x�NK
2+
�0t�S�� ILc
3+
"�+�@���M�뢷7"^@�� �b�Z�xF��h���b轴;�l��K����r�3<��3��3�Kc#-��"�k8�Z.��2�d�=�^*)ES�&�iq��ɏ��i��ϋP�j��A�y��3*H/

0 commit comments

Comments
 (0)
X Tutup