8000 Add string format ctor to all exceptions and change existing usages · repo-archive/libgit2sharp@0625b7f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0625b7f

Browse files
Oded WelgreenOded Welgreen
Oded Welgreen
authored and
Oded Welgreen
committed
Add string format ctor to all exceptions and change existing usages
1 parent 7dd95b8 commit 0625b7f

21 files changed

+158
-33
lines changed

LibGit2Sharp/BareRepositoryException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public BareRepositoryExceptio 10000 n(string message)
2525
: base(message)
2626
{ }
2727

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class with a specified error message.
30+
/// </summary>
31+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
32+
/// <param name="args">An object array that contains zero or more objects to format.</param>
33+
public BareRepositoryException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2837
/// <summary>
2938
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3039
/// </summary>

LibGit2Sharp/CheckoutConflictException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public CheckoutConflictException(string message)
2626
: base(message)
2727
{ }
2828

29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message.
31+
/// </summary>
32+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
33+
/// <param name="args">An object array that contains zero or more objects to format.</param>
34+
public CheckoutConflictException(string format, params object[] args)
35+
: base(format, args)
36+
{ }
37+
2938
/// <summary>
3039
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3140
/// </summary>

LibGit2Sharp/Core/Ensure.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,14 @@ public static void GitObjectIsNotNull(GitObject gitObject, string identifier)
261261
return;
262262
}
263263

264-
var message = string.Format(CultureInfo.InvariantCulture,
265-
"No valid git object identified by '{0}' exists in the repository.",
266-
identifier);
267-
264+
var messageFormat = "No valid git object identified by '{0}' exists in the repository.";
265+
268266
if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
269267
{
270-
throw new UnbornBranchException(message);
268+
throw new UnbornBranchException(messageFormat, identifier);
271269
}
272270

273-
throw new NotFoundException(message);
271+
throw new NotFoundException(messageFormat, identifier);
274272
}
275273
}
276274
}

LibGit2Sharp/Core/Proxy.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,7 @@ public static void git_filter_register(string name, IntPtr filterPtr, int priori
823823
int res = NativeMethods.git_filter_register(name, filterPtr, priority);
824824
if (res == (int)GitErrorCode.Exists)
825825
{
826-
var message = String.Format("A filter with the name '{0}' is already registered", name);
827-
throw new EntryExistsException(message);
826+
throw new EntryExistsException("A filter with the name '{0}' is already registered", name);
828827
}
829828
Ensure.ZeroResult(res);
830829
}
@@ -2256,7 +2255,7 @@ public static void git_remote_rename(RepositorySafeHandle repo, string name, str
22562255

22572256
if (res == (int)GitErrorCode.NotFound)
22582257
{
2259-
throw new NotFoundException(string.Format("Remote '{0}' does not exist and cannot be renamed.", name));
2258+
throw new NotFoundException("Remote '{0}' does not exist and cannot be renamed.", name);
22602259
}
22612260

22622261
Ensure.ZeroResult(res);
@@ -2404,9 +2403,8 @@ public static RepositorySafeHandle git_repository_open(string path)
24042403

24052404
if (res == (int)GitErrorCode.NotFound)
24062405
{
2407-
throw new RepositoryNotFoundException(String.Format(CultureInfo.InvariantCulture,
2408-
"Path '{0}' doesn't point at a valid Git repository or workdir.",
2409-
path));
2406+
throw new RepositoryNotFoundException("Path '{0}' doesn't point at a valid Git repository or workdir.",
2407+
path);
24102408
}
24112409

24122410
Ensure.ZeroResult(res);
@@ -2435,9 +2433,8 @@ public static void git_repository_open_ext(string path, RepositoryOpenFlags flag
24352433

24362434
if (res == (int)GitErrorCode.NotFound)
24372435
{
2438-
throw new RepositoryNotFoundException(String.Format(CultureInfo.InvariantCulture,
2439-
"Path '{0}' doesn't point at a valid Git repository or workdir.",
2440-
path));
2436+
throw new RepositoryNotFoundException("Path '{0}' doesn't point at a valid Git repository or workdir.",
2437+
path);
24412438
}
24422439

24432440
Ensure.ZeroResult(res);
@@ -3076,8 +3073,8 @@ public static void git_transport_register(String prefix, IntPtr transport_cb, In
30763073

30773074
if (res == (int)GitErrorCode.Exists)
30783075
{
3079-
throw new EntryExistsException(String.Format("A custom transport for '{0}' is already registered",
3080-
prefix));
3076+
throw new EntryExistsException("A custom transport for '{0}' is already registered",
3077+
prefix);
30813078
}
30823079

30833080
Ensure.ZeroResult(res);

LibGit2Sharp/EmptyCommitException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public EmptyCommitException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="EmptyCommitException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public EmptyCommitException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="EmptyCommitException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

LibGit2Sharp/EntryExistsException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public EntryExistsException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="LibGit2Sharp.EntryExistsException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public EntryExistsException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="LibGit2Sharp.EntryExistsException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

LibGit2Sharp/InvalidSpecificationException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public InvalidSpecificationException(string message)
2727
: base(message)
2828
{ }
2929

30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="InvalidSpecificationException"/> class with a specified error message.
32+
/// </summary>
33+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>. 10000 </param>
34+
/// <param name="args">An object array that contains zero or more objects to format.</param>
35+
public InvalidSpecificationException(string format, params object[] args)
36+
: base(format, args)
37+
{ }
38+
3039
/// <summary>
3140
/// Initializes a new instance of the <see cref="InvalidSpecificationException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3241
/// </summary>

LibGit2Sharp/LockedFileException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public LockedFileException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="LibGit2Sharp.LockedFileException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public LockedFileException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="LibGit2Sharp.LockedFileException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

LibGit2Sharp/MergeFetchHeadNotFoundException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ public MergeFetchHeadNotFoundException(string message)
2323
: base(message)
2424
{ }
2525

26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="MergeFetchHeadNotFoundException"/> class with a specified error message.
28+
/// </summary>
29+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
30+
/// <param name="args">An object array that contains zero or more objects to format.</param>
31+
public MergeFetchHeadNotFoundException(string format, params object[] args)
32+
: base(format, args)
33+
{ }
34+
2635
/// <summary>
2736
/// Initializes a new instance of the <see cref="MergeFetchHeadNotFoundException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2837
/// </summary>

LibGit2Sharp/NameConflictException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public NameConflictException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="NameConflictException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public NameConflictException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="NameConflictException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

LibGit2Sharp/NonFastForwardException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public NonFastForwardException(string message)
2525
: base(message)
2626
{ }
2727

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="LibGit2Sharp.NonFastForwardException"/> class with a specified error message.
30+
/// </summary>
31+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
32+
/// <param name="args">An object array that contains zero or more objects to format.</param>
33+
public NonFastForwardException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2837
/// <summary>
2938
/// Initializes a new instance of the <see cref="LibGit2Sharp.NonFastForwardException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3039
/// </summary>

LibGit2Sharp/NotFoundException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public NotFoundException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="LibGit2Sharp.NotFoundException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public NotFoundException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="LibGit2Sharp.NotFoundException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

LibGit2Sharp/PeelException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public PeelException(string message)
2525
: base(message)
2626
{ }
2727

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="PeelException"/> class with a specified error message.
30+
/// </summary>
31+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
32+
/// <param name="args">An object array that contains zero or more objects to format.</param>
33+
public PeelException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2837
/// <summary>
2938
/// Initializes a new instance of the <see cref="PeelException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3039
/// </summary>

LibGit2Sharp/ReflogCollection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ internal ReflogCollection(Repository repo, string canonicalName)
3737

3838
if (!Reference.IsValidName(canonicalName))
3939
{
40-
throw new InvalidSpecificationException(
41-
string.Format(CultureInfo.InvariantCulture, "The given reference name '{0}' is not valid", canonicalName));
40+
throw new InvalidSpecificationException("The given reference name '{0}' is not valid", canonicalName);
4241
}
4342

4443
this.repo = repo;

LibGit2Sharp/RemoveFromIndexException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RemoveFromIndexException(string message)
2525
{ }
2626

2727
/// <summary>
28-
/// Initializes a new instance of the <see cref="LibGit2SharpException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
28+
/// Initializes a new instance of the <see cref="RemoveFromIndexException"/> class with a specified error message.
2929
/// </summary>
3030
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
3131
/// <param name="args">An object array that contains zero or more objects to format.</param>

LibGit2Sharp/Repository.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,11 +1080,9 @@ public Commit Commit(string message, Signature author, Signature committer, Comm
10801080

10811081
if (treesame && !amendMergeCommit)
10821082
{
1083-
throw new EmptyCommitException(
1084-
options.AmendPreviousCommit ?
1085-
String.Format(CultureInfo.InvariantCulture,
1086-
"Amending this commit would produce a commit that is identical to its parent (id = {0})", parents[0].Id) :
1087-
"No changes; nothing to commit.");
1083+
throw (options.AmendPreviousCommit ?
1084+
new EmptyCommitException( 8000 "Amending this commit would produce a commit that is identical to its parent (id = {0})", parents[0].Id) :
1085+
new EmptyCommitException("No changes; nothing to commit."));
10881086
}
10891087
}
10901088

@@ -1273,8 +1271,8 @@ public MergeResult MergeFetchedRefs(Signature merger, MergeOptions options)
12731271
if (fetchHeads.Length == 0)
12741272
{
12751273
var expectedRef = this.Head.UpstreamBranchCanonicalName;
1276-
throw new MergeFetchHeadNotFoundException(string.Format(CultureInfo.InvariantCulture,
1277-
"The current branch is configured to merge with the reference '{0}' from the remote, but this reference was not fetched.", expectedRef));
1274+
throw new MergeFetchHeadNotFoundException("The current branch is configured to merge with the reference '{0}' from the remote, but this reference was not fetched.",
1275+
expectedRef);
12781276
}
12791277

12801278
GitAnnotatedCommitHandle[] annotatedCommitHandles = fetchHeads.Select(fetchHead =>

LibGit2Sharp/RepositoryNotFoundException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public RepositoryNotFoundException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="RepositoryNotFoundException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public RepositoryNotFoundException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="RepositoryNotFoundException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

LibGit2Sharp/SubmoduleCollection.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ public virtual void Init(string name, bool overwrite)
6262
{
6363
if (handle == null)
6464
{
65-
throw new NotFoundException(string.Format(CultureInfo.InvariantCulture,
66-
"Submodule lookup failed for '{0}'.",
67-
name));
65+
throw new NotFoundException("Submodule lookup failed for '{0}'.",
66+
name);
6867
}
6968

7069
Proxy.git_submodule_init(handle, overwrite);
@@ -90,9 +89,8 @@ public virtual void Update(string name, SubmoduleUpdateOptions options)
9089
{
9190
if (handle == null)
9291
{
93-
throw new NotFoundException(string.Format(CultureInfo.InvariantCulture,
94-
"Submodule lookup failed for '{0}'.",
95-
name));
92+
throw new NotFoundException("Submodule lookup failed for '{0}'.",
93+
name);
9694
}
9795

9896
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))

LibGit2Sharp/UnmatchedPathException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ public UnmatchedPathException(string message)
2323
: base(message)
2424
{ }
2525

26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="UnmatchedPathException"/> class with a specified error message.
28+
/// </summary>
29+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
30+
/// <param name="args">An object array that contains zero or more objects to format.</param>
31+
public UnmatchedPathException(string format, params object[] args)
32+
: base(format, args)
33+
{ }
34+
2635
/// <summary>
2736
/// Initializes a new instance of the <see cref="UnmatchedPathException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2837
/// </summary>

0 commit comments

Comments
 (0)
0