Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump gcm from v2.6.0 > v2.6.1 #122

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 131 additions & 114 deletions .netconfig

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ Supported [credential stores](https://github.com/git-ecosystem/git-credential-ma
configuration is shared with the GCM project itself.

<!-- #content -->

## Releasing

To create a new release:
1. Find & replace the latest release tag in this project to the desired release tag in
the [git-credential-manager](https://github.com/git-ecosystem/git-credential-manager/releases) project
in the .netconfig file
2. Run `dotnet file sync -c:$env:TEMP\dotnet-file.md`
3. Use the contents of the generated file to update the release notes in the GitHub release.
If no useful notes were generated, just copy the GCM ones.
4. Create a PR like [this one](https://github.com/devlooped/CredentialManager/pull/111)
5. Once merged, create a matching release in this project.

<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md -->
# Sponsors

Expand Down
4 changes: 4 additions & 0 deletions src/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static class CredentialStoreNames
public const string SecretService = "secretservice";
public const string Plaintext = "plaintext";
public const string Cache = "cache";
public const string None = "none";
}

public static class RegexPatterns
Expand Down Expand Up @@ -119,6 +120,7 @@ public static class EnvironmentVariables
public const string OAuthDefaultUserName = "GCM_OAUTH_DEFAULT_USERNAME";
public const string GcmDevUseLegacyUiHelpers = "GCM_DEV_USELEGACYUIHELPERS";
public const string GcmGuiSoftwareRendering = "GCM_GUI_SOFTWARE_RENDERING";
public const string GcmAllowUnsafeRemotes = "GCM_ALLOW_UNSAFE_REMOTES";
}

public static class Http
Expand Down Expand Up @@ -163,6 +165,7 @@ public static class Credential
public const string MsAuthUseDefaultAccount = "msauthUseDefaultAccount";
public const string GuiSoftwareRendering = "guiSoftwareRendering";
public const string GpgPassStorePath = "gpgPassStorePath";
public const string AllowUnsafeRemotes = "allowUnsafeRemotes";

public const string OAuthAuthenticationModes = "oauthAuthModes";
public const string OAuthClientId = "oauthClientId";
Expand Down Expand Up @@ -226,6 +229,7 @@ public static class HelpUrls
public const string GcmAutoDetect = "https://aka.ms/gcm/autodetect";
public const string GcmDefaultAccount = "https://aka.ms/gcm/defaultaccount";
public const string GcmMultipleUsers = "https://aka.ms/gcm/multipleusers";
public const string GcmUnsafeRemotes = "https://aka.ms/gcm/unsaferemotes";
}

private static Version _gcmVersion;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions src/Core/CredentialStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ private void EnsureBackingStore()
_backingStore = new PlaintextCredentialStore(_context.FileSystem, plainStoreRoot, ns);
break;

case StoreNames.None:
_backingStore = new NullCredentialStore();
break;

default:
var sb = new StringBuilder();
sb.AppendLine(string.IsNullOrWhiteSpace(credStoreName)
Expand Down Expand Up @@ -168,6 +172,9 @@ private static void AppendAvailableStoreList(StringBuilder sb)

sb.AppendFormat(" {1,-13} : store credentials in plain-text files (UNSECURE){0}",
Environment.NewLine, StoreNames.Plaintext);

sb.AppendFormat(" {1, -13} : disable internal credential storage{0}",
Environment.NewLine, StoreNames.None);
}

private void ValidateWindowsCredentialManager()
Expand Down
74 changes: 74 additions & 0 deletions src/Core/GitStreamReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace GitCredentialManager;

/// <summary>
/// StreamReader that does NOT consider a lone carriage-return as a new-line character,
/// only a line-feed or carriage-return immediately followed by a line-feed.
/// <para/>
/// The only major operating system that uses a lone carriage-return as a new-line character
/// is the classic Macintosh OS (before OS X), which is not supported by Git.
/// </summary>
public class GitStreamReader : StreamReader
{
public GitStreamReader(Stream stream, Encoding encoding) : base(stream, encoding) { }

public override string ReadLine()
{
#if NETFRAMEWORK
return ReadLineAsync().ConfigureAwait(false).GetAwaiter().GetResult();
#elif NETSTANDARD2_0
return ReadLineAsync().ConfigureAwait(false).GetAwaiter().GetResult();
#else
return ReadLineAsync(CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult();
#endif
}

#if NETFRAMEWORK
public override async Task<string> ReadLineAsync()
#elif NETSTANDARD2_0
public override async Task<string> ReadLineAsync()
#else
public override async ValueTask<string> ReadLineAsync(CancellationToken cancellationToken)
#endif
{
int nr;
var sb = new StringBuilder();
var buffer = new char[1];
bool lastWasCR = false;

while ((nr = await base.ReadAsync(buffer, 0, 1).ConfigureAwait(false)) > 0)
{
char c = buffer[0];

// Only treat a line-feed as a new-line character.
// Carriage-returns alone are NOT considered new-line characters.
if (c == '\n')
{
if (lastWasCR)
{
// If the last character was a carriage-return we should remove it from the string builder
// since together with this line-feed it is considered a new-line character.
sb.Length--;
}

// We have a new-line character, so we should stop reading.
break;
}

lastWasCR = c == '\r';

sb.Append(c);
}

if (sb.Length == 0 && nr == 0)
{
return null;
}

return sb.ToString();
}
}
19 changes: 19 additions & 0 deletions src/Core/NullCredentialStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;

namespace GitCredentialManager;

/// <summary>
/// Credential store that does nothing. This is useful when you want to disable internal credential storage
/// and only use another helper configured in Git to store credentials.
/// </summary>
public class NullCredentialStore : ICredentialStore
{
public IList<string> GetAccounts(string service) => Array.Empty<string>();

public ICredential Get(string service, string account) => null;

public void AddOrUpdate(string service, string account, string secret) { }

public bool Remove(string service, string account) => false;
}
11 changes: 11 additions & 0 deletions src/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ public interface ISettings : IDisposable
/// </summary>
bool UseSoftwareRendering { get; }

/// <summary>
/// Permit the use of unsafe remotes URLs such as regular HTTP.
/// </summary>
bool AllowUnsafeRemotes { get; }

/// <summary>
/// Get TRACE2 settings.
/// </summary>
Expand Down Expand Up @@ -580,6 +585,12 @@ public bool UseSoftwareRendering
}
}

public bool AllowUnsafeRemotes =>
TryGetSetting(KnownEnvars.GcmAllowUnsafeRemotes,
KnownGitCfg.Credential.SectionName,
KnownGitCfg.Credential.AllowUnsafeRemotes,
out string str) && str.ToBooleanyOrDefault(false);

public Trace2Settings GetTrace2Settings()
{
var settings = new Trace2Settings();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/StandardStreams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public TextReader In
{
if (_stdIn == null)
{
_stdIn = new StreamReader(Console.OpenStandardInput(), EncodingEx.UTF8NoBom);
_stdIn = new GitStreamReader(Console.OpenStandardInput(), EncodingEx.UTF8NoBom);
}

return _stdIn;
Expand Down
2 changes: 2 additions & 0 deletions src/CredentialManager/CredentialManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class SettingsWrapper(ISettings settings, string? @namespace) : ISettings

public bool UseSoftwareRendering => settings.UseSoftwareRendering;

public bool AllowUnsafeRemotes => settings.AllowUnsafeRemotes;

public void Dispose() => settings.Dispose();
public ProxyConfiguration GetProxyConfiguration() => settings.GetProxyConfiguration();
public IEnumerable<string> GetSettingValues(string envarName, string section, string property, bool isPath) => settings.GetSettingValues(envarName, section, property, isPath);
Expand Down
2 changes: 1 addition & 1 deletion src/SponsorLink/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.4.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="ThisAssembly.Resources" Version="2.0.10" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" />
Expand Down