Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for git push with custom headers #2011

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

Closed
wants to merge 3 commits into from
Closed
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
61 changes: 1 addition & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,63 +29,4 @@ jobs:
with:
name: NuGet packages
path: bin/Packages/
retention-days: 7
test:
name: Test / ${{ matrix.os }} / ${{ matrix.arch }} / ${{ matrix.tfm }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
arch: [ amd64 ]
os: [ windows-2019, macos-11 ]
tfm: [ net472, net6.0, net7.0 ]
exclude:
- os: macos-11
tfm: net472
fail-fast: false
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Install .NET SDK
uses: actions/[email protected]
with:
dotnet-version: |
7.0.x
6.0.x
- name: Run ${{ matrix.tfm }} tests
run: dotnet test LibGit2Sharp.sln --configuration Release --framework ${{ matrix.tfm }} --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
test-linux:
name: Test / ${{ matrix.distro }} / ${{ matrix.arch }} / ${{ matrix.tfm }}
runs-on: ubuntu-22.04
strategy:
matrix:
arch: [ amd64 ]
# arch: [ amd64, arm64 ]
distro: [ alpine.3.13, alpine.3.14, alpine.3.15, alpine.3.16, alpine.3.17, centos.7, centos.stream.8, debian.10, debian.11, fedora.36, ubuntu.18.04, ubuntu.20.04, ubuntu.22.04 ]
sdk: [ '6.0', '7.0' ]
exclude:
- distro: alpine.3.13
sdk: '7.0'
- distro: alpine.3.14
sdk: '7.0'
include:
- sdk: '6.0'
tfm: net6.0
- sdk: '7.0'
tfm: net7.0
fail-fast: false
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Setup QEMU
if: matrix.arch == 'arm64'
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
- name: Run ${{ matrix.tfm }} tests
run: |
git_command="git config --global --add safe.directory /app"
test_command="dotnet test LibGit2Sharp.sln --configuration Release -p:TargetFrameworks=${{ matrix.tfm }} --logger "GitHubActions" -p:ExtraDefine=LEAKS_IDENTIFYING"
docker run -t --rm --platform linux/${{ matrix.arch }} -v "$PWD:/app" gittools/build-images:${{ matrix.distro }}-sdk-${{ matrix.sdk }} sh -c "$git_command && $test_command"

retention-days: 7
7 changes: 4 additions & 3 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<PropertyGroup>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET</Description>
<Description>LibGit2Sharp-evolvedlight brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET</Description>
<Company>LibGit2Sharp contributors</Company>
<Copyright>Copyright © LibGit2Sharp contributors</Copyright>
<PackageTags>libgit2 git</PackageTags>
<PackageProjectUrl>https://github.com/libgit2/libgit2sharp/</PackageProjectUrl>
<PackageProjectUrl>https://github.com/evolvedlight/libgit2sharp/</PackageProjectUrl>
<Authors>LibGit2Sharp contributors</Authors>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageId>LibGit2Sharp-evolvedlight</PackageId>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugType>embedded</DebugType>
<SignAssembly>true</SignAssembly>
Expand Down Expand Up @@ -43,7 +44,7 @@

<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<PackageReleaseNotes>https://github.com/libgit2/libgit2sharp/blob/$(SourceRevisionId)/CHANGES.md</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/evolvedlight/libgit2sharp/blob/$(SourceRevisionId)/CHANGES.md</PackageReleaseNotes>
</PropertyGroup>
</Target>

Expand Down
1 change: 1 addition & 0 deletions LibGit2Sharp/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ public virtual void Push(Remote remote, IEnumerable<string> pushRefSpecs, PushOp
PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism,
RemoteCallbacks = gitCallbacks,
ProxyOptions = new GitProxyOptions { Version = 1 },
CustomHeaders = pushOptions.CustomHeaders?.Length > 0 ? GitStrArrayManaged.BuildFrom(pushOptions.CustomHeaders) : new GitStrArrayManaged()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is null better than new GitStrArrayManaged() here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CustomHeaders field is of type GitStrArrayManaged, which is a struct type so non-nullable value type. So not without some other impacting modifications I think.

Copy link
Contributor

@James-LG James-LG Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitStrArrayManaged needs to be disposed. I have a similar PR that does that here #2052 by following the pattern set by GitFetchOptionsWrapper.

});
}
}
Expand Down
21 changes: 21 additions & 0 deletions LibGit2Sharp/PushOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ public sealed class PushOptions
/// </summary>
public int PackbuilderDegreeOfParallelism { get; set; }

/// <summary>
/// Get/Set the custom headers.
///
/// <para>
/// This allows you to set custom headers (e.g. X-Forwarded-For,
/// X-Request-Id, etc),
/// </para>
/// </summary>
/// <remarks>
/// Libgit2 sets some headers for HTTP requests (User-Agent, Host,
/// Accept, Content-Type, Transfer-Encoding, Content-Length, Accept) that
/// cannot be overriden.
/// </remarks>
/// <example>
/// var fetchOptions - new FetchOptions() {
/// CustomHeaders = new String[] {"X-Request-Id: 12345"}
/// };
/// </example>
/// <value>The custom headers string array</value>
public string[] CustomHeaders { get; set; }

/// <summary>
/// Delegate to report errors when updating references on the remote.
/// </summary>
Expand Down