Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2015-06-16 08:48:53 +0300
committernulltoken <emeric.fermas@gmail.com>2015-06-16 08:48:53 +0300
commit687b4e0089b87ce1b5a62f5b2f279a148bc7e521 (patch)
treec3bdbcea06d8b5703cb259a44a7c8e785d249780
parent325ddfcd59e25ee5f93b24da5253da5c1b813dca (diff)
parent409a4a2ba0833e86293e6efdc565e64a883903c9 (diff)
Merge pull request #1095 from whoisj/add-format-exceptions
Adding support for message formatting in exception c'tors
-rw-r--r--LibGit2Sharp/AmbiguousSpecificationException.cs12
-rw-r--r--LibGit2Sharp/BranchCollection.cs6
-rw-r--r--LibGit2Sharp/Core/Proxy.cs13
-rw-r--r--LibGit2Sharp/Diff.cs24
-rw-r--r--LibGit2Sharp/GitObject.cs5
-rw-r--r--LibGit2Sharp/LibGit2SharpException.cs12
-rw-r--r--LibGit2Sharp/Reference.cs2
-rw-r--r--LibGit2Sharp/ReferenceCollectionExtensions.cs5
-rw-r--r--LibGit2Sharp/RemoveFromIndexException.cs12
-rw-r--r--LibGit2Sharp/Repository.cs43
-rw-r--r--LibGit2Sharp/RepositoryExtensions.cs2
-rw-r--r--LibGit2Sharp/SubmoduleCollection.cs4
-rw-r--r--LibGit2Sharp/UnbornBranchException.cs12
13 files changed, 110 insertions, 42 deletions
diff --git a/LibGit2Sharp/AmbiguousSpecificationException.cs b/LibGit2Sharp/AmbiguousSpecificationException.cs
index 3b9024cf..ec6352b6 100644
--- a/LibGit2Sharp/AmbiguousSpecificationException.cs
+++ b/LibGit2Sharp/AmbiguousSpecificationException.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.Runtime.Serialization;
namespace LibGit2Sharp
@@ -26,6 +27,17 @@ namespace LibGit2Sharp
}
/// <summary>
+ /// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class with a specified error message.
+ /// </summary>
+ /// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
+ /// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
+ /// <param name="args">An object array that contains zero or more objects to format.</param>
+ public AmbiguousSpecificationException(CultureInfo cultureInfo, string format, params object[] args)
+ : base(String.Format(cultureInfo, format, args))
+ {
+ }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs
index 42834d04..815cdbe3 100644
--- a/LibGit2Sharp/BranchCollection.cs
+++ b/LibGit2Sharp/BranchCollection.cs
@@ -174,9 +174,9 @@ namespace LibGit2Sharp
if (branch.IsRemote)
{
- throw new LibGit2SharpException(
- string.Format(CultureInfo.InvariantCulture,
- "Cannot rename branch '{0}'. It's a remote tracking branch.", branch.FriendlyName));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture,
+ "Cannot rename branch '{0}'. It's a remote tracking branch.",
+ branch.FriendlyName);
}
using (ReferenceSafeHandle referencePtr = repo.Refs.RetrieveReferencePtr(Reference.LocalBranchPrefix + branch.FriendlyName))
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 604587b9..5a52f066 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -2334,8 +2334,9 @@ namespace LibGit2Sharp.Core
return null;
case (int)GitErrorCode.Ambiguous:
- throw new AmbiguousSpecificationException(string.Format(CultureInfo.InvariantCulture,
- "Provided abbreviated ObjectId '{0}' is too short.", objectish));
+ throw new AmbiguousSpecificationException(CultureInfo.InvariantCulture,
+ "Provided abbreviated ObjectId '{0}' is too short.",
+ objectish);
default:
Ensure.ZeroResult(res);
@@ -2541,10 +2542,10 @@ namespace LibGit2Sharp.Core
return FileStatus.Nonexistent;
case (int)GitErrorCode.Ambiguous:
- throw new AmbiguousSpecificationException(string.Format(CultureInfo.InvariantCulture,
- "More than one file matches the pathspec '{0}'. " +
- "You can either force a literal path evaluation (GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH), or use git_status_foreach().",
- path));
+ throw new AmbiguousSpecificationException(CultureInfo.InvariantCulture,
+ "More than one file matches the pathspec '{0}'. " +
+ "You can either force a literal path evaluation (GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH), or use git_status_foreach().",
+ path);
default:
Ensure.ZeroResult(res);
diff --git a/LibGit2Sharp/Diff.cs b/LibGit2Sharp/Diff.cs
index 265aa0cd..911e2425 100644
--- a/LibGit2Sharp/Diff.cs
+++ b/LibGit2Sharp/Diff.cs
@@ -212,9 +212,11 @@ namespace LibGit2Sharp
if (!ChangesBuilders.TryGetValue(typeof (T), out builder))
{
- throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture,
- "Unexpected type '{0}' passed to Compare. Supported values are either '{1}' or '{2}'.", typeof (T),
- typeof (TreeChanges), typeof (Patch)));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture,
+ "Unexpected type '{0}' passed to Compare. Supported values are either '{1}' or '{2}'.",
+ typeof(T),
+ typeof(TreeChanges),
+ typeof(Patch));
}
var comparer = TreeToTree(repo);
@@ -323,9 +325,11 @@ namespace LibGit2Sharp
if (!ChangesBuilders.TryGetValue(typeof (T), out builder))
{
- throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture,
- "Unexpected type '{0}' passed to Compare. Supported values are either '{1}' or '{2}'.", typeof (T),
- typeof (TreeChanges), typeof (Patch)));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture,
+ "Unexpected type '{0}' passed to Compare. Supported values are either '{1}' or '{2}'.",
+ typeof(T),
+ typeof(TreeChanges),
+ typeof(Patch));
}
var comparer = HandleRetrieverDispatcher[diffTargets](repo);
@@ -453,9 +457,11 @@ namespace LibGit2Sharp
if (!ChangesBuilders.TryGetValue(typeof (T), out builder))
{
- throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture,
- "Unexpected type '{0}' passed to Compare. Supported values are either '{1}' or '{2}'.", typeof (T),
- typeof (TreeChanges), typeof (Patch)));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture,
+ "Unexpected type '{0}' passed to Compare. Supported values are either '{1}' or '{2}'.",
+ typeof(T),
+ typeof(TreeChanges),
+ typeof(Patch));
}
var comparer = WorkdirToIndex(repo);
diff --git a/LibGit2Sharp/GitObject.cs b/LibGit2Sharp/GitObject.cs
index 5e11489a..9dbce189 100644
--- a/LibGit2Sharp/GitObject.cs
+++ b/LibGit2Sharp/GitObject.cs
@@ -73,7 +73,10 @@ namespace LibGit2Sharp
case GitObjectType.Blob:
return new Blob(repo, id);
default:
- throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Unexpected type '{0}' for object '{1}'.", type, id));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture,
+ "Unexpected type '{0}' for object '{1}'.",
+ type,
+ id);
}
}
diff --git a/LibGit2Sharp/LibGit2SharpException.cs b/LibGit2Sharp/LibGit2SharpException.cs
index b80dba6d..d5947b02 100644
--- a/LibGit2Sharp/LibGit2SharpException.cs
+++ b/LibGit2Sharp/LibGit2SharpException.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;
@@ -37,6 +38,17 @@ namespace LibGit2Sharp
}
/// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
+ /// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
+ /// <param name="args">An object array that contains zero or more objects to format.</param>
+ public LibGit2SharpException(CultureInfo cultureInfo, string format, params object[] args)
+ : base(String.Format(cultureInfo, format, args))
+ {
+ }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="LibGit2SharpException"/> class with a serialized data.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
diff --git a/LibGit2Sharp/Reference.cs b/LibGit2Sharp/Reference.cs
index 35cf7b28..61fb907c 100644
--- a/LibGit2Sharp/Reference.cs
+++ b/LibGit2Sharp/Reference.cs
@@ -59,7 +59,7 @@ namespace LibGit2Sharp
break;
default:
- throw new LibGit2SharpException(String.Format(CultureInfo.InvariantCulture, "Unable to build a new reference from a type '{0}'.", type));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture, "Unable to build a new reference from a type '{0}'.", type);
}
return reference as T;
diff --git a/LibGit2Sharp/ReferenceCollectionExtensions.cs b/LibGit2Sharp/ReferenceCollectionExtensions.cs
index 5fb2f6dd..0e97ea54 100644
--- a/LibGit2Sharp/ReferenceCollectionExtensions.cs
+++ b/LibGit2Sharp/ReferenceCollectionExtensions.cs
@@ -256,7 +256,10 @@ namespace LibGit2Sharp
return refsColl.UpdateTarget(symbolicReference, targetRef, logMessage);
}
- throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Reference '{0}' has an unexpected type ('{1}').", name, reference.GetType()));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture,
+ "Reference '{0}' has an unexpected type ('{1}').",
+ name,
+ reference.GetType());
}
/// <summary>
diff --git a/LibGit2Sharp/RemoveFromIndexException.cs b/LibGit2Sharp/RemoveFromIndexException.cs
index 57bfbafa..9f086312 100644
--- a/LibGit2Sharp/RemoveFromIndexException.cs
+++ b/LibGit2Sharp/RemoveFromIndexException.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.Runtime.Serialization;
namespace LibGit2Sharp
@@ -26,6 +27,17 @@ namespace LibGit2Sharp
}
/// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
+ /// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
+ /// <param name="args">An object array that contains zero or more objects to format.</param>
+ public RemoveFromIndexException(CultureInfo cultureInfo, string format, params object[] args)
+ : base(cultureInfo, format, args)
+ {
+ }
+
+ /// <summary>
/// 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.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index f219e9e1..0a400727 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -889,9 +889,7 @@ namespace LibGit2Sharp
// Make sure this is not an unborn branch.
if (branch.Tip == null)
{
- throw new UnbornBranchException(
- string.Format(CultureInfo.InvariantCulture,
- "The tip of branch '{0}' is null. There's nothing to checkout.", branch.FriendlyName));
+ throw new UnbornBranchException(CultureInfo.InvariantCulture, "The tip of branch '{0}' is null. There's nothing to checkout.", branch.FriendlyName);
}
if (!branch.IsRemote && !(branch is DetachedHead) &&
@@ -1550,7 +1548,7 @@ namespace LibGit2Sharp
Version = 1,
MergeFileFavorFlags = options.MergeFileFavor,
MergeTreeFlags = options.FindRenames ? GitMergeTreeFlags.GIT_MERGE_TREE_FIND_RENAMES :
- GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
+ GitMergeTreeFlags.GIT_MERGE_TREE_NORMAL,
RenameThreshold = (uint) options.RenameThreshold,
TargetLimit = (uint) options.TargetLimit,
};
@@ -1848,7 +1846,10 @@ namespace LibGit2Sharp
FileStatus sourceStatus = keyValuePair.Key.Item2;
if (sourceStatus.HasAny(new Enum[] { FileStatus.Nonexistent, FileStatus.DeletedFromIndex, FileStatus.NewInWorkdir, FileStatus.DeletedFromWorkdir }))
{
- throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Unable to move file '{0}'. Its current status is '{1}'.", sourcePath, sourceStatus));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture,
+ "Unable to move file '{0}'. Its current status is '{1}'.",
+ sourcePath,
+ sourceStatus);
}
FileStatus desStatus = keyValuePair.Value.Item2;
@@ -1857,7 +1858,10 @@ namespace LibGit2Sharp
continue;
}
- throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Unable to overwrite file '{0}'. Its current status is '{1}'.", destPath, desStatus));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture,
+ "Unable to overwrite file '{0}'. Its current status is '{1}'.",
+ destPath,
+ desStatus);
}
string wd = Info.WorkingDirectory;
@@ -2090,8 +2094,9 @@ namespace LibGit2Sharp
status.HasFlag(FileStatus.ModifiedInIndex) ||
status.HasFlag(FileStatus.NewInIndex) ))
{
- throw new RemoveFromIndexException(string.Format(CultureInfo.InvariantCulture, "Unable to remove file '{0}', as it has changes staged in the index. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.",
- treeEntryChanges.Path));
+ throw new RemoveFromIndexException(CultureInfo.InvariantCulture,
+ "Unable to remove file '{0}', as it has changes staged in the index. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.",
+ treeEntryChanges.Path);
}
removed.Add(RemoveFromIndex(treeEntryChanges.Path));
continue;
@@ -2099,20 +2104,24 @@ namespace LibGit2Sharp
case ChangeKind.Modified:
if (status.HasFlag(FileStatus.ModifiedInWorkdir) && status.HasFlag(FileStatus.ModifiedInIndex))
{
- throw new RemoveFromIndexException(string.Format(CultureInfo.InvariantCulture, "Unable to remove file '{0}', as it has staged content different from both the working directory and the HEAD.",
- treeEntryChanges.Path));
+ throw new RemoveFromIndexException(CultureInfo.InvariantCulture,
+ "Unable to remove file '{0}', as it has staged content different from both the working directory and the HEAD.",
+ treeEntryChanges.Path);
}
if (removeFromWorkingDirectory)
{
- throw new RemoveFromIndexException(string.Format(CultureInfo.InvariantCulture, "Unable to remove file '{0}', as it has local modifications. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.",
- treeEntryChanges.Path));
+ throw new RemoveFromIndexException(CultureInfo.InvariantCulture,
+ "Unable to remove file '{0}', as it has local modifications. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.",
+ treeEntryChanges.Path);
}
removed.Add(RemoveFromIndex(treeEntryChanges.Path));
continue;
default:
- throw new RemoveFromIndexException(string.Format(CultureInfo.InvariantCulture, "Unable to remove file '{0}'. Its current status is '{1}'.",
- treeEntryChanges.Path, treeEntryChanges.Status));
+ throw new RemoveFromIndexException(CultureInfo.InvariantCulture,
+ "Unable to remove file '{0}'. Its current status is '{1}'.",
+ treeEntryChanges.Path,
+ treeEntryChanges.Status);
}
}
@@ -2148,9 +2157,9 @@ namespace LibGit2Sharp
get
{
return string.Format(CultureInfo.InvariantCulture,
- "{0} = \"{1}\"",
- Info.IsBare ? "Gitdir" : "Workdir",
- Info.IsBare ? Info.Path : Info.WorkingDirectory);
+ "{0} = \"{1}\"",
+ Info.IsBare ? "Gitdir" : "Workdir",
+ Info.IsBare ? Info.Path : Info.WorkingDirectory);
}
}
}
diff --git a/LibGit2Sharp/RepositoryExtensions.cs b/LibGit2Sharp/RepositoryExtensions.cs
index 57f7b860..385c5a9a 100644
--- a/LibGit2Sharp/RepositoryExtensions.cs
+++ b/LibGit2Sharp/RepositoryExtensions.cs
@@ -466,7 +466,7 @@ namespace LibGit2Sharp
if (throwIfNotFound)
{
- throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Unexpected kind of identifier '{0}'.", identifier));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture, "Unexpected kind of identifier '{0}'.", identifier);
}
yield return null;
diff --git a/LibGit2Sharp/SubmoduleCollection.cs b/LibGit2Sharp/SubmoduleCollection.cs
index 14ff416a..4c9a61fe 100644
--- a/LibGit2Sharp/SubmoduleCollection.cs
+++ b/LibGit2Sharp/SubmoduleCollection.cs
@@ -160,9 +160,7 @@ namespace LibGit2Sharp
if (throwIfNotFound)
{
- throw new LibGit2SharpException(string.Format(
- CultureInfo.InvariantCulture,
- "Submodule lookup failed for '{0}'.", name));
+ throw new LibGit2SharpException(CultureInfo.InvariantCulture, "Submodule lookup failed for '{0}'.", name);
}
return default(T);
diff --git a/LibGit2Sharp/UnbornBranchException.cs b/LibGit2Sharp/UnbornBranchException.cs
index 2704d1a9..ac2b1ee2 100644
--- a/LibGit2Sharp/UnbornBranchException.cs
+++ b/LibGit2Sharp/UnbornBranchException.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.Runtime.Serialization;
namespace LibGit2Sharp
@@ -27,6 +28,17 @@ namespace LibGit2Sharp
}
/// <summary>
+ /// Initializes a new instance of the <see cref="UnbornBranchException"/> class with a specified error message.
+ /// </summary>
+ /// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
+ /// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
+ /// <param name="args">An object array that contains zero or more objects to format.</param>
+ public UnbornBranchException(CultureInfo cultureInfo, string format, params object[] args)
+ : base(String.Format(cultureInfo, format, args))
+ {
+ }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="UnbornBranchException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>