From 7d285c0956395fbc471366959f0399fe29d6f304 Mon Sep 17 00:00:00 2001 From: Colin Dean Date: Tue, 5 Aug 2025 11:48:39 -0400 Subject: [PATCH 1/3] diagnostic: Use pushd/popd in uncommited modifications nudge While filing https://github.com/Homebrew/brew/issues/20379, I lost where I was because I followed the given instruction. Instead, let's use pushd/popd so the user is returned to their pwd if the git operations succeed. --- Library/Homebrew/diagnostic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index fee9f2bf4b..33a6f77e6c 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -703,7 +703,7 @@ module Homebrew If this is a surprise to you, then you should stash these modifications. Stashing returns Homebrew to a pristine state but can be undone should you later need to do so for some reason. - cd #{path} && git stash -u && git clean -d -f + pushd #{path} && git stash -u && git clean -d -f && popd EOS modified = status.split("\n") From 60ce25bea07a96a9c9a006021df89bee55a558da Mon Sep 17 00:00:00 2001 From: Colin Dean Date: Tue, 5 Aug 2025 14:49:11 -0400 Subject: [PATCH 2/3] Use git's -C option to set git's working directory for uncommitted modifications nudge --- Library/Homebrew/diagnostic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 33a6f77e6c..1606f47315 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -703,7 +703,7 @@ module Homebrew If this is a surprise to you, then you should stash these modifications. Stashing returns Homebrew to a pristine state but can be undone should you later need to do so for some reason. - pushd #{path} && git stash -u && git clean -d -f && popd + git stash -u -C #{path} && git clean -d -f -C #{path} EOS modified = status.split("\n") From f08122937f6b0ee47ecd69fe7983eea5b3dad2dc Mon Sep 17 00:00:00 2001 From: Colin Dean Date: Tue, 5 Aug 2025 14:58:44 -0400 Subject: [PATCH 3/3] Reorders git options for uncommitted modifications nudge -C path must come before the subcommand. Co-authored-by: Carlo Cabrera --- Library/Homebrew/diagnostic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 1606f47315..589e53b1c7 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -703,7 +703,7 @@ module Homebrew If this is a surprise to you, then you should stash these modifications. Stashing returns Homebrew to a pristine state but can be undone should you later need to do so for some reason. - git stash -u -C #{path} && git clean -d -f -C #{path} + git -C "#{path}" stash -u && git -C "${path}" clean -d -f EOS modified = status.split("\n")