Skip to content

Draft: Add new exception types for different GitErrorCodes #22

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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
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
42 changes: 42 additions & 0 deletions .github/workflows/Build_and_publish_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and Deploy Packages

on:
pull_request:
push:
branches:
- main

jobs:
build:
# Currently we build LibGit2Sharp for Windows only
# See: https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#configuring-a-build-matrix
runs-on: windows-2019

steps:
# Checkout repo into build area
- uses: actions/checkout@v3
with:
fetch-depth: 0 # avoid shallow clone so Nerdbank.GitVersioning can do its work.

# Build and deploy nuget package
# We include the GitHub package source so that we can reference current packages and also so that we can push to the package repo
- name: Build Project and Package
run: |
dotnet nuget add source "https://nuget.pkg.github.com/mendix/index.json" --name "GitHub" --username ${{ secrets.GHPACKAGESUSER }} --password ${{ secrets.GHPACKAGESTOKEN }}
dotnet pack --configuration Release --output "mx_nuget" -p:PublicRelease=true LibGit2Sharp/LibGit2Sharp.csproj
shell: powershell #Keep as powershell and not pwsh

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: nuget package
path: ${{ github.workspace }}/**/*.nupkg

# After build we copy the binaries to package output folder
# Finally we pack and push the package to github packages
- name: Deploy Package
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
dotnet nuget add source "https://nuget.pkg.github.com/mendix/index.json" --name "GitHub" --username ${{ secrets.GHPACKAGESUSER }} --password ${{ secrets.GHPACKAGESTOKEN }}
dotnet nuget push "**/mx_nuget/Mendix.LibGit2Sharp*.nupkg" --source "GitHub" --skip-duplicate
shell: powershell #Keep as powershell and not pwsh
98 changes: 0 additions & 98 deletions .github/workflows/ci.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .mailmap

This file was deleted.

24 changes: 12 additions & 12 deletions LibGit2Sharp.Tests/CloneFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void CanCloneWithCheckoutBranchName(string branchName, string headTipId)
{
var scd = BuildSelfCleaningDirectory();

string clonedRepoPath = Repository.Clone(BareTestRepoPath, scd.DirectoryPath, new CloneOptions { BranchName = branchName });
string clonedRepoPath = Repository.Clone(BareTestRepoPath, scd.DirectoryPath, new CloneOptions { BranchName = branchName }, new ProxyOptions());

using (var repo = new Repository(clonedRepoPath))
{
Expand Down Expand Up @@ -107,7 +107,7 @@ public void CanCloneBarely(string url)
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions
{
IsBare = true
});
}, new ProxyOptions());

using (var repo = new Repository(clonedRepoPath))
{
Expand All @@ -130,7 +130,7 @@ public void WontCheckoutIfAskedNotTo(string url)
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
{
Checkout = false
});
}, new ProxyOptions());

using (var repo = new Repository(clonedRepoPath))
{
Expand All @@ -155,7 +155,7 @@ public void CallsProgressCallbacks(string url)
OnProgress = progress => { progressWasCalled = true; return true; },
OnUpdateTips = (name, oldId, newId) => { updateTipsWasCalled = true; return true; },
OnCheckoutProgress = (a, b, c) => checkoutWasCalled = true
});
}, new ProxyOptions());

Assert.True(transferWasCalled);
Assert.True(progressWasCalled);
Expand All @@ -175,7 +175,7 @@ public void CanCloneWithCredentials()
new CloneOptions()
{
CredentialsProvider = Constants.PrivateRepoCredentials
});
}, new ProxyOptions());


using (var repo = new Repository(clonedRepoPath))
Expand Down Expand Up @@ -289,7 +289,7 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
};

Assert.Throws<UserCancelledException>(() =>
Repository.Clone(url, scd.DirectoryPath, options)
Repository.Clone(url, scd.DirectoryPath, options, new ProxyOptions())
);

Assert.True(wasCalled);
Expand Down Expand Up @@ -437,7 +437,7 @@ public void CanRecursivelyCloneSubmodules()
RepositoryOperationCompleted = repositoryOperationCompleted,
};

string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options, new ProxyOptions());
string workDirPath;

using (Repository repo = new Repository(clonedRepoPath))
Expand Down Expand Up @@ -521,7 +521,7 @@ public void CanCancelRecursiveClone()
};

Assert.Throws<UserCancelledException>(() =>
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options));
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options, new ProxyOptions()));

// Cancel after super repository is cloned, but before submodule is cloned.
cancelDepth = 1;
Expand All @@ -530,7 +530,7 @@ public void CanCancelRecursiveClone()

try
{
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options, new ProxyOptions());
}
catch (RecurseSubmodulesException ex)
{
Expand Down Expand Up @@ -562,7 +562,7 @@ public void CannotCloneWithForbiddenCustomHeaders()
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
};

Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions));
Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions, new ProxyOptions()));
}

[Fact]
Expand All @@ -578,7 +578,7 @@ public void CannotCloneWithMalformedCustomHeaders()
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
};

Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions));
Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions, new ProxyOptions()));
}

[Fact]
Expand All @@ -594,7 +594,7 @@ public void CanCloneWithCustomHeaders()
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
};

var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, cloneOptions);
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, cloneOptions, new ProxyOptions());
Assert.True(Directory.Exists(clonedRepoPath));
}
}
Expand Down
26 changes: 14 additions & 12 deletions LibGit2Sharp.Tests/FetchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using LibGit2Sharp.Core;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;

Expand Down Expand Up @@ -42,7 +43,7 @@ public void CanFetchIntoAnEmptyRepository(string url)
}

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null, new ProxyOptions());

// Verify the expected
expectedFetchState.CheckUpdatedReferences(repo);
Expand All @@ -65,7 +66,7 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
{
CredentialsProvider = Constants.PrivateRepoCredentials
}, null);
}, null, new ProxyOptions());
}
}

Expand Down Expand Up @@ -102,7 +103,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
{
TagFetchMode = TagFetchMode.All,
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
}, null);
}, null, new ProxyOptions());

// Verify the expected
expectedFetchState.CheckUpdatedReferences(repo);
Expand Down Expand Up @@ -148,7 +149,7 @@ public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string local
{
TagFetchMode = TagFetchMode.None,
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
}, null);
}, null, new ProxyOptions());

// Verify the expected
expectedFetchState.CheckUpdatedReferences(repo);
Expand Down Expand Up @@ -179,7 +180,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int
r => r.TagFetchMode = tagFetchMode);

// Perform the actual fetch.
Commands.Fetch(repo, remoteName, new string[0], null, null);
Commands.Fetch(repo, remoteName, new string[0], null, null, null);

// Verify the number of fetched tags.
Assert.Equal(expectedTagCount, repo.Tags.Count());
Expand All @@ -197,7 +198,7 @@ public void CanFetchAllTagsAfterAnInitialClone()

using (var repo = new Repository(clonedRepoPath))
{
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null, new ProxyOptions());
}
}

Expand All @@ -223,17 +224,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()

// No pruning when the configuration entry isn't defined
Assert.Null(clonedRepo.Config.Get<bool>("fetch.prune"));
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null, null);
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));

// No pruning when the configuration entry is set to false
clonedRepo.Config.Set<bool>("fetch.prune", false);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null, null);
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));

// Auto pruning when the configuration entry is set to true
clonedRepo.Config.Set<bool>("fetch.prune", true);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null, null);
Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
}
}
Expand All @@ -251,7 +252,8 @@ public void CannotFetchWithForbiddenCustomHeaders()
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
var ex = Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null, new ProxyOptions()));
Assert.Equal(GitErrorCategory.Invalid, ex.Category);
}
}

Expand All @@ -268,7 +270,7 @@ public void CanFetchWithCustomHeaders()
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Commands.Fetch(repo, "origin", new string[0], options, null);
Commands.Fetch(repo, "origin", new string[0], options, null, new ProxyOptions());
}
}

Expand All @@ -285,7 +287,7 @@ public void CannotFetchWithMalformedCustomHeaders()
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null, new ProxyOptions()));
}
}

Expand Down
Loading