Skip to content

Commit 57a566a

Browse files
committed
macos environment: ignore homebrew shim
Ignore Homebrew shim to ensure the user's installed version of Git is called during `brew uninstall` (instead of the shim). Note that this involves explicitly passing the HOMEBREW_PREFIX environment variable, since the `sudo -u `/usr/bin/logname` "$GCMBIN" unconfigure` command does not inherit it.
1 parent b5f7f28 commit 57a566a

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/osx/Installer.Mac/uninstall.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fi
1212

1313
# Unconfigure (as the current user)
1414
echo "Unconfiguring credential helper..."
15-
sudo -u `/usr/bin/logname` "$GCMBIN" unconfigure
15+
sudo -u `/usr/bin/logname` -E "$GCMBIN" unconfigure
1616

1717
# Remove symlink
1818
if [ -L /usr/local/bin/git-credential-manager-core ]

src/shared/Core/CommandContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public CommandContext(string appPath)
107107
FileSystem = new MacOSFileSystem();
108108
SessionManager = new MacOSSessionManager();
109109
SystemPrompts = new MacOSSystemPrompts();
110-
Environment = new PosixEnvironment(FileSystem);
110+
Environment = new MacOSEnvironment(FileSystem);
111111
Terminal = new MacOSTerminal(Trace);
112112
string gitPath = GetGitPath(Environment, FileSystem, Trace);
113113
Git = new GitProcess(
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Threading;
6+
using GitCredentialManager.Interop.Posix;
7+
8+
namespace GitCredentialManager.Interop.MacOS
9+
{
10+
public class MacOSEnvironment : PosixEnvironment
11+
{
12+
private ICollection<string> _pathsToIgnore;
13+
14+
public MacOSEnvironment(IFileSystem fileSystem)
15+
: base(fileSystem) { }
16+
17+
internal MacOSEnvironment(IFileSystem fileSystem, IReadOnlyDictionary<string, string> variables)
18+
: base(fileSystem)
19+
{
20+
EnsureArgument.NotNull(variables, nameof(variables));
21+
Variables = variables;
22+
}
23+
24+
public override bool TryLocateExecutable(string program, out string path)
25+
{
26+
if (_pathsToIgnore is null)
27+
{
28+
_pathsToIgnore = new List<string>();
29+
if (Variables.TryGetValue("HOMEBREW_PREFIX", out string homebrewPrefix))
30+
{
31+
string homebrewGit = Path.Combine(homebrewPrefix, "Homebrew/Library/Homebrew/shims/shared/git");
32+
_pathsToIgnore.Add(homebrewGit);
33+
}
34+
}
35+
return TryLocateExecutable(program, _pathsToIgnore, out path);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)