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

Csharp friendly errors #163

Closed
wants to merge 2 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
42 changes: 8 additions & 34 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
# Catch all for anything we forgot. Add rules if you get CRLF to LF warnings.
# Auto detect text files and perform LF normalization
* text=auto

# Text files that should be normalized to LF in odb.
*.cs text diff=csharp
*.config text

*.sln text
*.csproj text

*.md text
*.sh text
*.ps1 text
*.cmd text
*.bat text
*.markdown text
*.msbuild text

Lib/* binary
GitHub.Tests.Integration/Resources/* binary


# Binary files that should not be normalized or diffed
*.png binary
*.jpg binary
*.gif binary

*.pfx binary
*.snk binary
*.dll binary
*.exe binary
*.lib binary
*.exp binary
*.pdb binary
*.sdf binary
*.7z binary
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
16 changes: 8 additions & 8 deletions LibGit2Sharp.Tests/BranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ public void CreatingABranchFromANonCommitObjectThrows()
using (var repo = new Repository(BareTestRepoPath))
{
const string name = "sorry-dude-i-do-not-do-blobs-nor-trees";
Assert.Throws<LibGit2Exception>(() => repo.CreateBranch(name, "refs/tags/point_to_blob"));
Assert.Throws<LibGit2Exception>(() => repo.CreateBranch(name, "53fc32d"));
Assert.Throws<LibGit2Exception>(() => repo.CreateBranch(name, "0266163"));
Assert.Throws<LibGit2SharpException>(() => repo.CreateBranch(name, "refs/tags/point_to_blob"));
Assert.Throws<LibGit2SharpException>(() => repo.CreateBranch(name, "53fc32d"));
Assert.Throws<LibGit2SharpException>(() => repo.CreateBranch(name, "0266163"));
}
}

Expand All @@ -136,7 +136,7 @@ public void CreatingBranchWithUnknownNamedTargetThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Branches.Create("my_new_branch", "my_old_branch"));
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Create("my_new_branch", "my_old_branch"));
}
}

Expand All @@ -145,8 +145,8 @@ public void CreatingBranchWithUnknownShaTargetThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Branches.Create("my_new_branch", Constants.UnknownSha));
Assert.Throws<LibGit2Exception>(() => repo.Branches.Create("my_new_branch", Constants.UnknownSha.Substring(0, 7)));
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Create("my_new_branch", Constants.UnknownSha));
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Create("my_new_branch", Constants.UnknownSha.Substring(0, 7)));
}
}

Expand All @@ -155,7 +155,7 @@ public void CreatingABranchPointingAtANonCanonicalReferenceThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Branches.Create("nocanonicaltarget", "br2"));
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Create("nocanonicaltarget", "br2"));
}
}

Expand Down Expand Up @@ -414,7 +414,7 @@ public void CheckingOutANonExistingBranchThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Checkout("i-do-not-exist"));
Assert.Throws<LibGit2SharpException>(() => repo.Checkout("i-do-not-exist"));
}
}

Expand Down
10 changes: 5 additions & 5 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public void QueryingTheCommitHistoryWithUnknownShaOrInvalidEntryPointThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Commits.QueryBy(new Filter { Since = Constants.UnknownSha }).Count());
Assert.Throws<LibGit2Exception>(() => repo.Commits.QueryBy(new Filter { Since = "refs/heads/deadbeef" }).Count());
Assert.Throws<LibGit2SharpException>(() => repo.Commits.QueryBy(new Filter { Since = Constants.UnknownSha }).Count());
Assert.Throws<LibGit2SharpException>(() => repo.Commits.QueryBy(new Filter { Since = "refs/heads/deadbeef" }).Count());
Assert.Throws<ArgumentNullException>(() => repo.Commits.QueryBy(new Filter { Since = null }).Count());
}
}
Expand All @@ -110,8 +110,8 @@ public void QueryingTheCommitHistoryFromACorruptedReferenceThrows()
{
CreateCorruptedDeadBeefHead(repo.Info.Path);

Assert.Throws<LibGit2Exception>(() => repo.Commits.QueryBy(new Filter { Since = repo.Branches["deadbeef"] }).Count());
Assert.Throws<LibGit2Exception>(() => repo.Commits.QueryBy(new Filter { Since = repo.Refs["refs/heads/deadbeef"] }).Count());
Assert.Throws<LibGit2SharpException>(() => repo.Commits.QueryBy(new Filter { Since = repo.Branches["deadbeef"] }).Count());
Assert.Throws<LibGit2SharpException>(() => repo.Commits.QueryBy(new Filter { Since = repo.Refs["refs/heads/deadbeef"] }).Count());
}
}

Expand Down Expand Up @@ -647,7 +647,7 @@ public void CanNotAmendAnEmptyRepository()

using (Repository repo = Repository.Init(scd.DirectoryPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Commit("I can not amend anything !:(", DummySignature, DummySignature, true));
Assert.Throws<LibGit2SharpException>(() => repo.Commit("I can not amend anything !:(", DummySignature, DummySignature, true));
}
}

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/ConfigurationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void SettingLocalConfigurationOutsideAReposThrows()
{
using (var config = new Configuration())
{
Assert.Throws<LibGit2Exception>(() => config.Set("unittests.intsetting", 3));
Assert.Throws<LibGit2SharpException>(() => config.Set("unittests.intsetting", 3));
}
}

Expand Down
18 changes: 15 additions & 3 deletions LibGit2Sharp.Tests/IndexFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,26 @@ public void CanStageTheUpdationOfAStagedFile()

[Theory]
[InlineData("1/I-do-not-exist.txt", FileStatus.Nonexistent)]
[InlineData("deleted_staged_file.txt", FileStatus.Removed)]
public void StagingAnUnknownFileThrows(string relativePath, FileStatus status)
{
using (var repo = new Repository(StandardTestRepoPath))
{
Assert.Null(repo.Index[relativePath]);
Assert.Equal(status, repo.Index.RetrieveStatus(relativePath));

Assert.Throws<LibGit2SharpException>(() => repo.Index.Stage(relativePath));
}
}

[Theory]
[InlineData("deleted_staged_file.txt", FileStatus.Removed)]
public void StagingARemovedFileThrows(string relativePath, FileStatus status)
{
using (var repo = new Repository(StandardTestRepoPath))
{
Assert.Null(repo.Index[relativePath]);
Assert.Equal(repo.Index.RetrieveStatus(relativePath), status);

Assert.Throws<LibGit2Exception>(() => repo.Index.Stage(relativePath));
}
}
Expand Down Expand Up @@ -457,7 +469,7 @@ private static void InvalidMoveUseCases(string sourcePath, FileStatus sourceStat
foreach (var destPath in destPaths)
{
string path = destPath;
Assert.Throws<LibGit2Exception>(() => repo.Index.Move(sourcePath, path));
Assert.Throws<LibGit2SharpException>(() => repo.Index.Move(sourcePath, path));
}
}
}
Expand Down Expand Up @@ -493,7 +505,7 @@ public void RemovingAInvalidFileThrows(string filepath)
{
using (var repo = new Repository(StandardTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Index.Remove(filepath));
Assert.Throws<LibGit2SharpException>(() => repo.Index.Remove(filepath));
}
}

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void AccessingTheIndexInABareRepoThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Index);
Assert.Throws<LibGit2SharpException>(() => repo.Index);
}
}

Expand Down
6 changes: 3 additions & 3 deletions LibGit2Sharp.Tests/ResetFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ResetANewlyInitializedRepositoryThrows(bool isBare)

using (var repo = Repository.Init(scd.DirectoryPath, isBare))
{
Assert.Throws<LibGit2Exception>(() => repo.Reset(ResetOptions.Soft, repo.Head.CanonicalName));
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft, repo.Head.CanonicalName));
}
}

Expand Down Expand Up @@ -54,7 +54,7 @@ public void ResettingWithBadParamsThrows()
{
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, null));
Assert.Throws<ArgumentException>(() => repo.Reset(ResetOptions.Soft, ""));
Assert.Throws<LibGit2Exception>(() => repo.Reset(ResetOptions.Soft, Constants.UnknownSha));
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft, Constants.UnknownSha));
}
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public void MixedResetInABareRepositoryThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Reset(ResetOptions.Mixed, repo.Head.Tip.Sha));
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Mixed, repo.Head.Tip.Sha));
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions LibGit2Sharp.Tests/TagFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void CreatingATagInAEmptyRepositoryThrows()

using (var repo = Repository.Init(scd.DirectoryPath))
{
Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("mynotag"));
Assert.Throws<LibGit2SharpException>(() => repo.ApplyTag("mynotag"));
}
}

Expand All @@ -187,7 +187,7 @@ public void CreatingATagForHeadInAEmptyRepositoryThrows()

using (var repo = Repository.Init(scd.DirectoryPath))
{
Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("mytaghead", "HEAD"));
Assert.Throws<LibGit2SharpException>(() => repo.ApplyTag("mytaghead", "HEAD"));
}
}

Expand All @@ -197,7 +197,7 @@ public void CreatingATagForAnUnknowReferenceThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("mytagnorev", "aaaaaaaaaaa"));
Assert.Throws<LibGit2SharpException>(() => repo.ApplyTag("mytagnorev", "aaaaaaaaaaa"));
}
}

Expand All @@ -206,7 +206,7 @@ public void CreatingATagForANonCanonicalReferenceThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("noncanonicaltarget", "br2"));
Assert.Throws<LibGit2SharpException>(() => repo.ApplyTag("noncanonicaltarget", "br2"));
}
}

Expand All @@ -216,7 +216,7 @@ public void CreatingATagForAnUnknowObjectIdThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("mytagnorev", Constants.UnknownSha));
Assert.Throws<LibGit2SharpException>(() => repo.ApplyTag("mytagnorev", Constants.UnknownSha));
}
}

Expand Down Expand Up @@ -408,7 +408,7 @@ public void CreateTagWithNotExistingTargetThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Tags.Create("test_tag", Constants.UnknownSha, signatureTim, "message"));
Assert.Throws<LibGit2SharpException>(() => repo.Tags.Create("test_tag", Constants.UnknownSha, signatureTim, "message"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/BranchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void Delete(string name, bool isRemote = false)

int res = NativeMethods.git_branch_delete(repo.Handle, name, isRemote ? GitBranchType.GIT_BRANCH_REMOTE : GitBranchType.GIT_BRANCH_LOCAL);

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return;
}
Expand Down
8 changes: 4 additions & 4 deletions LibGit2Sharp/CommitCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public Commit FindCommonAncestor(Commit first, Commit second)
GitOid ret;
int result = NativeMethods.git_merge_base(out ret, repo.Handle, osw1.ObjectPtr, osw2.ObjectPtr);

if (result == (int)GitErrorCode.GIT_ENOTFOUND)
if (result == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ public Commit Create(string message, Signature author, Signature committer, bool
{
if (amendPreviousCommit && repo.Info.IsEmpty)
{
throw new LibGit2Exception("Can not amend anything. The Head doesn't point at any commit.");
throw new LibGit2SharpException("Can not amend anything. The Head doesn't point at any commit.");
}

GitOid treeOid;
Expand Down Expand Up @@ -270,7 +270,7 @@ public bool MoveNext()
GitOid oid;
int res = NativeMethods.git_revwalk_next(out oid, handle);

if (res == (int)GitErrorCode.GIT_EREVWALKOVER)
if (res == (int)GitErrorCode.RevWalkOver)
{
return false;
}
Expand Down Expand Up @@ -404,7 +404,7 @@ private IEnumerable<ObjectId> RetrieveCommitOids(object identifier)
yield break;
}

throw new LibGit2Exception(string.Format(CultureInfo.InvariantCulture, "Unexpected kind of identifier '{0}'.", identifier));
throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Unexpected kind of identifier '{0}'.", identifier));
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions LibGit2Sharp/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static string ConvertPath(Func<byte[], uint, int> pathRetriever)

int result = pathRetriever(buffer, NativeMethods.GIT_PATH_MAX);

if (result == (int)GitErrorCode.GIT_ENOTFOUND)
if (result == (int)GitErrorCode.NotFound)
{
return null;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ public void Delete(string key, ConfigurationLevel level = ConfigurationLevel.Loc

int res = NativeMethods.git_config_delete(h, key);

if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return;
}
Expand Down Expand Up @@ -201,7 +201,7 @@ public T Get<T>(string key, T defaultValue)
ConfigurationSafeHandle handle = (LocalHandle ?? globalHandle) ?? systemHandle;
if (handle == null)
{
throw new LibGit2Exception("Could not find a local, global or system level configuration.");
throw new LibGit2SharpException("Could not find a local, global or system level configuration.");
}

return (T)configurationTypedRetriever[typeof(T)](key, defaultValue, handle);
Expand Down Expand Up @@ -339,17 +339,17 @@ private ConfigurationSafeHandle RetrieveConfigurationHandle(ConfigurationLevel l
{
if (level == ConfigurationLevel.Local && !HasLocalConfig)
{
throw new LibGit2Exception("No local configuration file has been found. You must use ConfigurationLevel.Global when accessing configuration outside of repository.");
throw new LibGit2SharpException("No local configuration file has been found. You must use ConfigurationLevel.Global when accessing configuration outside of repository.");
}

if (level == ConfigurationLevel.Global && !HasGlobalConfig)
{
throw new LibGit2Exception("No global configuration file has been found.");
throw new LibGit2SharpException("No global configuration file has been found.");
}

if (level == ConfigurationLevel.System && !HasSystemConfig)
{
throw new LibGit2Exception("No system configuration file has been found.");
throw new LibGit2SharpException("No system configuration file has been found.");
}

ConfigurationSafeHandle h;
Expand Down Expand Up @@ -382,7 +382,7 @@ private static Func<string, object, ConfigurationSafeHandle, object> GetRetrieve
{
T value;
var res = getter(out value, handle, key);
if (res == (int)GitErrorCode.GIT_ENOTFOUND)
if (res == (int)GitErrorCode.NotFound)
{
return defaultValue;
}
Expand Down
Loading