X Tutup
Skip to content

Commit dd34cae

Browse files
committed
Merge remote-tracking branch 'origin' into cancel-error-status
2 parents 2ebdde1 + 50c49df commit dd34cae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1856
-207
lines changed

api/cache.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,13 @@ func (fs *fileStorage) store(key string, res *http.Response) error {
167167
defer f.Close()
168168

169169
var origBody io.ReadCloser
170-
origBody, res.Body = copyStream(res.Body)
171-
defer res.Body.Close()
170+
if res.Body != nil {
171+
origBody, res.Body = copyStream(res.Body)
172+
defer res.Body.Close()
173+
}
172174
err = res.Write(f)
173-
res.Body = origBody
175+
if origBody != nil {
176+
res.Body = origBody
177+
}
174178
return err
175179
}

cmd/gh/main.go

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

170170
newRelease := <-updateMessageChan
171171
if newRelease != nil {
172-
ghExe, _ := os.Executable()
172+
isHomebrew := false
173+
if ghExe, err := os.Executable(); err == nil {
174+
isHomebrew = isUnderHomebrew(ghExe)
175+
}
176+
if isHomebrew && isRecentRelease(newRelease.PublishedAt) {
177+
// do not notify Homebrew users before the version bump had a chance to get merged into homebrew-core
178+
return
179+
}
173180
fmt.Fprintf(stderr, "\n\n%s %s → %s\n",
174181
ansi.Color("A new release of gh is available:", "yellow"),
175182
ansi.Color(buildVersion, "cyan"),
176183
ansi.Color(newRelease.Version, "cyan"))
177-
if suggestBrewUpgrade(newRelease, ghExe) {
184+
if isHomebrew {
178185
fmt.Fprintf(stderr, "To upgrade, run: %s\n", "brew update && brew upgrade gh")
179186
}
180187
fmt.Fprintf(stderr, "%s\n\n",
@@ -267,13 +274,12 @@ func apiVerboseLog() api.ClientOption {
267274
return api.VerboseLog(colorable.NewColorable(os.Stderr), logTraffic, colorize)
268275
}
269276

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

281+
// Check whether the gh binary was found under the Homebrew prefix
282+
func isUnderHomebrew(ghBinary string) bool {
277283
brewExe, err := safeexec.LookPath("brew")
278284
if err != nil {
279285
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.

0 commit comments

Comments
 (0)
X Tutup