Skip to content

Commit 51d560a

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 5218c83 commit 51d560a

23 files changed

+186
-56
lines changed

LibGit2Sharp/AmbiguousSpecificationException.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ public AmbiguousSpecificationException(string message)
2727
/// <summary>
2828
/// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class with a specified error message.
2929
/// </summary>
30-
/// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
3130
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
3231
/// <param name="args">An object array that contains zero or more objects to format.</param>
33-
public AmbiguousSpecificationException(CultureInfo cultureInfo, string format, params object[] args)
34-
: base(String.Format(cultureInfo, format, args))
32+
public AmbiguousSpecificationException(string format, params object[] args)
33+
: base(format, args)
3534
{
3635
}
3736

LibGit2Sharp/BareRepositoryException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33
using LibGit2Sharp.Core;
4+
using System.Globalization;
45

56
namespace LibGit2Sharp
67
{
@@ -25,6 +26,15 @@ public BareRepositoryException(string message)
2526
: base(message)
2627
{ }
2728

29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> 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 BareRepositoryException(string format, params object[] args)
35+
: base(format, args)
36+
{ }
37+
2838
/// <summary>
2939
/// 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.
3040
/// </summary>

LibGit2Sharp/CheckoutConflictException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33
using LibGit2Sharp.Core;
4+
using System.Globalization;
45

56
namespace LibGit2Sharp
67
{
@@ -26,6 +27,15 @@ public CheckoutConflictException(string message)
2627
: base(message)
2728
{ }
2829

30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> 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[])"/>.</param>
34+
/// <param name="args">An object array that contains zero or more objects to format.</param>
35+
public CheckoutConflictException(string format, params object[] args)
36+
: base(format, args)
37+
{ }
38+
2939
/// <summary>
3040
/// 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.
3141
/// </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: 10 additions & 15 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);
@@ -2555,8 +2552,7 @@ public static Tuple<GitObjectSafeHandle, ReferenceSafeHandle> git_revparse_ext(R
25552552
return null;
25562553

25572554
case (int)GitErrorCode.Ambiguous:
2558-
throw new AmbiguousSpecificationException(CultureInfo.InvariantCulture,
2559-
"Provided abbreviated ObjectId '{0}' is too short.",
2555+
throw new AmbiguousSpecificationException("Provided abbreviated ObjectId '{0}' is too short.",
25602556
objectish);
25612557

25622558
default:
@@ -2777,8 +2773,7 @@ public static FileStatus git_status_file(RepositorySafeHandle repo, FilePath pat
27772773
return FileStatus.Nonexistent;
27782774

27792775
case (int)GitErrorCode.Ambiguous:
2780-
throw new AmbiguousSpecificationException(CultureInfo.InvariantCulture,
2781-
"More than one file matches the pathspec '{0}'. " +
2776+
throw new AmbiguousSpecificationException("More than one file matches the pathspec '{0}'. " +
27822777
"You can either force a literal path evaluation " +
27832778
"(GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH), or use git_status_foreach().",
27842779
path);
@@ -3078,8 +3073,8 @@ public static void git_transport_register(String prefix, IntPtr transport_cb, In
30783073

30793074
if (res == (int)GitErrorCode.Exists)
30803075
{
3081-
throw new EntryExistsException(String.Format("A custom transport for '{0}' is already registered",
3082-
prefix));
3076+
throw new EntryExistsException("A custom transport for '{0}' is already registered",
3077+
prefix);
30833078
}
30843079

30853080
Ensure.ZeroResult(res);

LibGit2Sharp/EmptyCommitException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23
using System.Runtime.Serialization;
34

45
namespace LibGit2Sharp
@@ -24,6 +25,15 @@ public EmptyCommitException(string message)
2425
: base(message)
2526
{ }
2627

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="EmptyCommitException"/> 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 EmptyCommitException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2737
/// <summary>
2838
/// 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.
2939
/// </summary>

LibGit2Sharp/EntryExistsException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33
using LibGit2Sharp.Core;
4+
using System.Globalization;
45

56
namespace LibGit2Sharp
67
{
@@ -24,6 +25,15 @@ public EntryExistsException(string message)
2425
: base(message)
2526
{ }
2627

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="LibGit2Sharp.EntryExistsException"/> 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 EntryExistsException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2737
/// <summary>
2838
/// 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.
2939
/// </summary>

LibGit2Sharp/InvalidSpecificationException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33
using LibGit2Sharp.Core;
4+
using System.Globalization;
45

56
namespace LibGit2Sharp
67
{
@@ -27,6 +28,15 @@ public InvalidSpecificationException(string message)
2728
: base(message)
2829
{ }
2930

31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="InvalidSpecificationException"/> class with a specified error message.
33+
/// </summary>
34+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
35+
/// <param name="args">An object array that contains zero or more objects to format.</param>
36+
public InvalidSpecificationException(string format, params object[] args)
37+
: base(format, args)
38+
{ }
39+
3040
/// <summary>
3141
/// 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.
3242
/// </summary>

LibGit2Sharp/LockedFileException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33
using LibGit2Sharp.Core;
4+
using System.Globalization;
45

56
namespace LibGit2Sharp
67
{
@@ -24,6 +25,15 @@ public LockedFileException(string message)
2425
: base(message)
2526
{ }
2627

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="LibGit2Sharp.LockedFileException"/> 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 LockedFileException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2737
/// <summary>
2838
/// 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.
2939
/// </summary>

LibGit2Sharp/MergeFetchHeadNotFoundException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23
using System.Runtime.Serialization;
34

45
namespace LibGit2Sharp
@@ -23,6 +24,15 @@ public MergeFetchHeadNotFoundException(string message)
2324
: base(message)
2425
{ }
2526

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="MergeFetchHeadNotFoundException"/> 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 MergeFetchHeadNotFoundException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2636
/// <summary>
2737
/// 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.
2838
/// </summary>

LibGit2Sharp/NameConflictException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33
using LibGit2Sharp.Core;
4+
using System.Globalization;
45

56
namespace LibGit2Sharp
67
{
@@ -24,6 +25,15 @@ public NameConflictException(string message)
2425
: base(message)
2526
{ }
2627

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="NameConflictException"/> 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 NameConflictException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2737
/// <summary>
2838
/// 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.
2939
/// </summary>

LibGit2Sharp/NonFastForwardException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33
using LibGit2Sharp.Core;
4+
using System.Globalization;
45

56
namespace LibGit2Sharp
67
{
@@ -25,6 +26,15 @@ public NonFastForwardException(string message)
2526
: base(message)
2627
{ }
2728

29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="LibGit2Sharp.NonFastForwardException"/> 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 NonFastForwardException(string format, params object[] args)
35+
: base(format, args)
36+
{ }
37+
2838
/// <summary>
2939
/// 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.
3040
/// </summary>

LibGit2Sharp/NotFoundException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33
using LibGit2Sharp.Core;
4+
using System.Globalization;
45

56
namespace LibGit2Sharp
67
{
@@ -24,6 +25,15 @@ public NotFoundException(string message)
2425
: base(message)
2526
{ }
2627

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="LibGit2Sharp.NotFoundException"/> 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 NotFoundException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2737
/// <summary>
2838
/// 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.
2939
/// </summary>

LibGit2Sharp/PeelException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33
using LibGit2Sharp.Core;
4+
using System.Globalization;
45

56
namespace LibGit2Sharp
67
{
@@ -25,6 +26,15 @@ public PeelException(string message)
2526
: base(message)
2627
{ }
2728

29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="PeelException"/> 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 PeelException(string format, params object[] args)
35+
: base(format, args)
36+
{ }
37+
2838
/// <summary>
2939
/// 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.
3040
/// </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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ 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="UnmatchedPathException"/> class with a specified error message.
2929
/// </summary>
30-
/// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
3130
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
3231
/// <param name="args">An object array that contains zero or more objects to format.</param>
33-
public RemoveFromIndexException(CultureInfo cultureInfo, string format, params object[] args)
34-
: base(cultureInfo, format, args)
32+
public RemoveFromIndexException(string format, params object[] args)
33+
: base(format, args)
3534
{
3635
}
3736

0 commit comments

Comments
 (0)