diff options
-rw-r--r-- | LibGit2Sharp.Tests/ConfigurationFixture.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/MetaFixture.cs | 54 | ||||
-rw-r--r-- | LibGit2Sharp.sln.DotSettings | 2 | ||||
-rw-r--r-- | LibGit2Sharp/BlobExtensions.cs | 33 | ||||
-rw-r--r-- | LibGit2Sharp/BranchCollection.cs | 26 | ||||
-rw-r--r-- | LibGit2Sharp/BranchCollectionExtensions.cs | 39 | ||||
-rw-r--r-- | LibGit2Sharp/CommitRewriteInfo.cs | 46 | ||||
-rw-r--r-- | LibGit2Sharp/Configuration.cs | 66 | ||||
-rw-r--r-- | LibGit2Sharp/ConfigurationExtensions.cs | 67 | ||||
-rw-r--r-- | LibGit2Sharp/Diff.cs | 218 | ||||
-rw-r--r-- | LibGit2Sharp/Network.cs | 186 | ||||
-rw-r--r-- | LibGit2Sharp/NetworkExtensions.cs | 29 | ||||
-rw-r--r-- | LibGit2Sharp/ObjectDatabase.cs | 79 | ||||
-rw-r--r-- | LibGit2Sharp/ReferenceCollection.cs | 81 | ||||
-rw-r--r-- | LibGit2Sharp/ReferenceCollectionExtensions.cs | 73 | ||||
-rw-r--r-- | LibGit2Sharp/RemoteCollection.cs | 13 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 47 | ||||
-rw-r--r-- | LibGit2Sharp/RepositoryExtensions.cs | 61 | ||||
-rw-r--r-- | LibGit2Sharp/StashCollection.cs | 33 | ||||
-rw-r--r-- | LibGit2Sharp/TagCollection.cs | 28 | ||||
-rw-r--r-- | LibGit2Sharp/TagCollectionExtensions.cs | 28 |
21 files changed, 1128 insertions, 83 deletions
diff --git a/LibGit2Sharp.Tests/ConfigurationFixture.cs b/LibGit2Sharp.Tests/ConfigurationFixture.cs index 4f92ce0c..78cb71c0 100644 --- a/LibGit2Sharp.Tests/ConfigurationFixture.cs +++ b/LibGit2Sharp.Tests/ConfigurationFixture.cs @@ -256,7 +256,7 @@ namespace LibGit2Sharp.Tests [Fact] public void SettingLocalConfigurationOutsideAReposThrows() { - using (var config = new Configuration()) + using (var config = new Configuration(null, null, null)) { Assert.Throws<LibGit2SharpException>(() => config.Set("unittests.intsetting", 3)); } diff --git a/LibGit2Sharp.Tests/MetaFixture.cs b/LibGit2Sharp.Tests/MetaFixture.cs index df0a1d96..685ff5f4 100644 --- a/LibGit2Sharp.Tests/MetaFixture.cs +++ b/LibGit2Sharp.Tests/MetaFixture.cs @@ -299,5 +299,59 @@ namespace LibGit2Sharp.Tests Assert.True(false, Environment.NewLine + sb.ToString()); } } + + [Fact] + public void NoOptionalParametersinMethods() + { + IEnumerable<string> mis = + from t in Assembly.GetAssembly(typeof(IRepository)) + .GetExportedTypes() + from m in t.GetMethods() + where !m.IsObsolete() + from p in m.GetParameters() + where p.IsOptional + select m.DeclaringType + "." + m.Name; + + var sb = new StringBuilder(); + + foreach (var method in mis.Distinct()) + { + sb.AppendFormat("At least one overload of method '{0}' accepts an optional parameter.{1}", + method, Environment.NewLine); + } + + Assert.Equal("", sb.ToString()); + } + + [Fact] + public void NoOptionalParametersinConstructors() + { + IEnumerable<string> mis = + from t in Assembly.GetAssembly(typeof(IRepository)) + .GetExportedTypes() + from c in t.GetConstructors() + from p in c.GetParameters() + where p.IsOptional + select c.DeclaringType.Name; + + var sb = new StringBuilder(); + + foreach (var method in mis.Distinct()) + { + sb.AppendFormat("At least one constructor of type '{0}' accepts an optional parameter.{1}", + method, Environment.NewLine); + } + + Assert.Equal("", sb.ToString()); + } + } + + internal static class TypeExtensions + { + internal static bool IsObsolete(this MethodInfo methodInfo) + { + var attributes = methodInfo.GetCustomAttributes(false); + return attributes.Any(a => a is ObsoleteAttribute); + } } } diff --git a/LibGit2Sharp.sln.DotSettings b/LibGit2Sharp.sln.DotSettings index ce4b3194..8bc2282a 100644 --- a/LibGit2Sharp.sln.DotSettings +++ b/LibGit2Sharp.sln.DotSettings @@ -10,6 +10,8 @@ <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHING_EMPTY_BRACES/@EntryValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean> + <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String> + <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean> </wpf:ResourceDictionary> diff --git a/LibGit2Sharp/BlobExtensions.cs b/LibGit2Sharp/BlobExtensions.cs index 0b38c32f..7dade3ce 100644 --- a/LibGit2Sharp/BlobExtensions.cs +++ b/LibGit2Sharp/BlobExtensions.cs @@ -10,21 +10,44 @@ namespace LibGit2Sharp public static class BlobExtensions { /// <summary> + /// Gets the blob content, decoded with UTF8 encoding if the encoding cannot be detected from the byte order mark + /// </summary> + /// <param name="blob">The blob for which the content will be returned.</param> + /// <returns>Blob content as text.</returns> + public static string GetContentText(this Blob blob) + { + Ensure.ArgumentNotNull(blob, "blob"); + + return ReadToEnd(blob.GetContentStream(), null); + } + + /// <summary> /// Gets the blob content decoded with the specified encoding, - /// or according to byte order marks, with UTF8 as fallback, - /// if <paramref name="encoding"/> is null. + /// or according to byte order marks, or the specified encoding as a fallback /// </summary> /// <param name="blob">The blob for which the content will be returned.</param> - /// <param name="encoding">The encoding of the text. (default: detected or UTF8)</param> + /// <param name="encoding">The encoding of the text to use, if it cannot be detected</param> /// <returns>Blob content as text.</returns> - public static string GetContentText(this Blob blob, Encoding encoding = null) + public static string GetContentText(this Blob blob, Encoding encoding) { Ensure.ArgumentNotNull(blob, "blob"); + Ensure.ArgumentNotNull(encoding, "encoding"); return ReadToEnd(blob.GetContentStream(), encoding); } /// <summary> + /// Gets the blob content, decoded with UTF8 encoding if the encoding cannot be detected + /// </summary> + /// <param name="blob">The blob for which the content will be returned.</param> + /// <param name="filteringOptions">Parameter controlling content filtering behavior</param> + /// <returns>Blob content as text.</returns> + public static string GetContentText(this Blob blob, FilteringOptions filteringOptions) + { + return blob.GetContentText(filteringOptions, null); + } + + /// <summary> /// Gets the blob content as it would be checked out to the /// working directory, decoded with the specified encoding, /// or according to byte order marks, with UTF8 as fallback, @@ -34,7 +57,7 @@ namespace LibGit2Sharp /// <param name="filteringOptions">Parameter controlling content filtering behavior</param> /// <param name="encoding">The encoding of the text. (default: detected or UTF8)</param> /// <returns>Blob content as text.</returns> - public static string GetContentText(this Blob blob, FilteringOptions filteringOptions, Encoding encoding = null) + public static string GetContentText(this Blob blob, FilteringOptions filteringOptions, Encoding encoding) { Ensure.ArgumentNotNull(blob, "blob"); Ensure.ArgumentNotNull(filteringOptions, "filteringOptions"); diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs index b4e617b2..42834d04 100644 --- a/LibGit2Sharp/BranchCollection.cs +++ b/LibGit2Sharp/BranchCollection.cs @@ -111,9 +111,20 @@ namespace LibGit2Sharp /// </summary> /// <param name="name">The name of the branch.</param> /// <param name="committish">Revparse spec for the target commit.</param> + /// <returns>A new <see cref="Branch"/>.</returns> + public virtual Branch Add(string name, string committish) + { + return Add(name, committish, false); + } + + /// <summary> + /// Create a new local branch with the specified name + /// </summary> + /// <param name="name">The name of the branch.</param> + /// <param name="committish">Revparse spec for the target commit.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param> /// <returns>A new <see cref="Branch"/>.</returns> - public virtual Branch Add(string name, string committish, bool allowOverwrite = false) + public virtual Branch Add(string name, string committish, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(committish, "committish"); @@ -143,9 +154,20 @@ namespace LibGit2Sharp /// </summary> /// <param name="branch">The current local branch.</param> /// <param name="newName">The new name the existing branch should bear.</param> + /// <returns>A new <see cref="Branch"/>.</returns> + public virtual Branch Rename(Branch branch, string newName) + { + return Rename(branch, newName, false); + } + + /// <summary> + /// Rename an existing local branch + /// </summary> + /// <param name="branch">The current local branch.</param> + /// <param name="newName">The new name the existing branch should bear.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param> /// <returns>A new <see cref="Branch"/>.</returns> - public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite = false) + public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite) { Ensure.ArgumentNotNull(branch, "branch"); Ensure.ArgumentNotNullOrEmptyString(newName, "newName"); diff --git a/LibGit2Sharp/BranchCollectionExtensions.cs b/LibGit2Sharp/BranchCollectionExtensions.cs index cea02c7a..68b15dec 100644 --- a/LibGit2Sharp/BranchCollectionExtensions.cs +++ b/LibGit2Sharp/BranchCollectionExtensions.cs @@ -13,15 +13,36 @@ namespace LibGit2Sharp /// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param> /// <param name="name">The name of the branch.</param> /// <param name="commit">The target commit.</param> + /// <returns>A new <see cref="Branch"/>.</returns> + public static Branch Add(this BranchCollection branches, string name, Commit commit) + { + return branches.Add(name, commit, false); + } + + /// <summary> + /// Create a new local branch with the specified name + /// </summary> + /// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param> + /// <param name="name">The name of the branch.</param> + /// <param name="commit">The target commit.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param> /// <returns>A new <see cref="Branch"/>.</returns> - public static Branch Add(this BranchCollection branches, string name, Commit commit, bool allowOverwrite = false) + public static Branch Add(this BranchCollection branches, string name, Commit commit, bool allowOverwrite) { Ensure.ArgumentNotNull(commit, "commit"); return branches.Add(name, commit.Sha, allowOverwrite); } + /// <summary> + /// Deletes the branch with the specified name. + /// </summary> + /// <param name="name">The name of the branch to delete.</param> + /// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param> + public static void Remove(this BranchCollection branches, string name) + { + branches.Remove(name, false); + } /// <summary> /// Deletes the branch with the specified name. @@ -29,7 +50,7 @@ namespace LibGit2Sharp /// <param name="name">The name of the branch to delete.</param> /// <param name="isRemote">True if the provided <paramref name="name"/> is the name of a remote branch, false otherwise.</param> /// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param> - public static void Remove(this BranchCollection branches, string name, bool isRemote = false) + public static void Remove(this BranchCollection branches, string name, bool isRemote) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); @@ -50,10 +71,22 @@ namespace LibGit2Sharp /// </summary> /// <param name="currentName">The current branch name.</param> /// <param name="newName">The new name the existing branch should bear.</param> + /// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param> + /// <returns>A new <see cref="Branch"/>.</returns> + public static Branch Rename(this BranchCollection branches, string currentName, string newName) + { + return branches.Rename(currentName, newName, false); + } + + /// <summary> + /// Rename an existing local branch, using the default reflog message + /// </summary> + /// <param name="currentName">The current branch name.</param> + /// <param name="newName">The new name the existing branch should bear.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param> /// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param> /// <returns>A new <see cref="Branch"/>.</returns> - public static Branch Rename(this BranchCollection branches, string currentName, string newName, bool allowOverwrite = false) + public static Branch Rename(this BranchCollection branches, string currentName, string newName, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName"); Ensure.ArgumentNotNullOrEmptyString(newName, "newName"); diff --git a/LibGit2Sharp/CommitRewriteInfo.cs b/LibGit2Sharp/CommitRewriteInfo.cs index 5e0a5caa..a4387e83 100644 --- a/LibGit2Sharp/CommitRewriteInfo.cs +++ b/LibGit2Sharp/CommitRewriteInfo.cs @@ -35,6 +35,46 @@ namespace LibGit2Sharp }; } + /// <summary> + /// Build a <see cref="CommitRewriteInfo"/> from the <see cref="Commit"/> passed in, + /// optionally overriding some of its properties + /// </summary> + /// <param name="commit">The <see cref="Commit"/> whose information is to be copied</param> + /// <param name="author">Optional override for the author</param> + /// <returns>A new <see cref="CommitRewriteInfo"/> object that matches the info for the + /// <paramref name="commit"/> with the optional parameters replaced..</returns> + public static CommitRewriteInfo From(Commit commit, Signature author) + { + return From(commit, author, null, null); + } + + /// <summary> + /// Build a <see cref="CommitRewriteInfo"/> from the <see cref="Commit"/> passed in, + /// optionally overriding some of its properties + /// </summary> + /// <param name="commit">The <see cref="Commit"/> whose information is to be copied</param> + /// <param name="message">Optional override for the message</param> + /// <returns>A new <see cref="CommitRewriteInfo"/> object that matches the info for the + /// <paramref name="commit"/> with the optional parameters replaced..</returns> + public static CommitRewriteInfo From(Commit commit, string message) + { + return From(commit, null, null, message); + } + + /// <summary> + /// Build a <see cref="CommitRewriteInfo"/> from the <see cref="Commit"/> passed in, + /// optionally overriding some of its properties + /// </summary> + /// <param name="commit">The <see cref="Commit"/> whose information is to be copied</param> + /// <param name="author">Optional override for the author</param> + /// <param name="committer">Optional override for the committer</param> + /// <returns>A new <see cref="CommitRewriteInfo"/> object that matches the info for the + /// <paramref name="commit"/> with the optional parameters replaced..</returns> + public static CommitRewriteInfo From(Commit commit, Signature author, Signature committer) + { + return From(commit, author, committer, null); + } + /// <summary> /// Build a <see cref="CommitRewriteInfo"/> from the <see cref="Commit"/> passed in, /// optionally overriding some of its properties @@ -46,9 +86,9 @@ namespace LibGit2Sharp /// <returns>A new <see cref="CommitRewriteInfo"/> object that matches the info for the /// <paramref name="commit"/> with the optional parameters replaced..</returns> public static CommitRewriteInfo From(Commit commit, - Signature author = null, - Signature committer = null, - string message = null) + Signature author, + Signature committer, + string message) { var cri = From(commit); cri.Author = author ?? cri.Author; diff --git a/LibGit2Sharp/Configuration.cs b/LibGit2Sharp/Configuration.cs index b1b57456..078ad14f 100644 --- a/LibGit2Sharp/Configuration.cs +++ b/LibGit2Sharp/Configuration.cs @@ -77,9 +77,26 @@ namespace LibGit2Sharp /// Access configuration values without a repository. Generally you want to access configuration via an instance of <see cref="Repository"/> instead. /// </summary> /// <param name="globalConfigurationFileLocation">Path to a Global configuration file. If null, the default path for a global configuration file will be probed.</param> + public Configuration(string globalConfigurationFileLocation) + : this(null, globalConfigurationFileLocation, null, null) + { } + + /// <summary> + /// Access configuration values without a repository. Generally you want to access configuration via an instance of <see cref="Repository"/> instead. + /// </summary> + /// <param name="globalConfigurationFileLocation">Path to a Global configuration file. If null, the default path for a global configuration file will be probed.</param> + /// <param name="xdgConfigurationFileLocation">Path to a XDG configuration file. If null, the default path for a XDG configuration file will be probed.</param> + public Configuration(string globalConfigurationFileLocation, string xdgConfigurationFileLocation) + : this(null, globalConfigurationFileLocation, xdgConfigurationFileLocation, null) + { } + + /// <summary> + /// Access configuration values without a repository. Generally you want to access configuration via an instance of <see cref="Repository"/> instead. + /// </summary> + /// <param name="globalConfigurationFileLocation">Path to a Global configuration file. If null, the default path for a global configuration file will be probed.</param> /// <param name="xdgConfigurationFileLocation">Path to a XDG configuration file. If null, the default path for a XDG configuration file will be probed.</param> /// <param name="systemConfigurationFileLocation">Path to a System configuration file. If null, the default path for a system configuration file will be probed.</param> - public Configuration(string globalConfigurationFileLocation = null, string xdgConfigurationFileLocation = null, string systemConfigurationFileLocation = null) + public Configuration(string globalConfigurationFileLocation, string xdgConfigurationFileLocation, string systemConfigurationFileLocation) : this(null, globalConfigurationFileLocation, xdgConfigurationFileLocation, systemConfigurationFileLocation) { } @@ -111,11 +128,20 @@ namespace LibGit2Sharp #endregion /// <summary> + /// Unset a configuration variable (key and value) in the local configuration. + /// </summary> + /// <param name="key">The key to unset.</param> + public virtual void Unset(string key) + { + Unset(key, ConfigurationLevel.Local); + } + + /// <summary> /// Unset a configuration variable (key and value). /// </summary> /// <param name="key">The key to unset.</param> /// <param name="level">The configuration file which should be considered as the target of this operation</param> - public virtual void Unset(string key, ConfigurationLevel level = ConfigurationLevel.Local) + public virtual void Unset(string key, ConfigurationLevel level) { Ensure.ArgumentNotNullOrEmptyString(key, "key"); @@ -210,6 +236,27 @@ namespace LibGit2Sharp } /// <summary> + /// Set a configuration value for a key in the local configuration. Keys are in the form 'section.name'. + /// <para> + /// For example in order to set the value for this in a .git\config file: + /// + /// [test] + /// boolsetting = true + /// + /// You would call: + /// + /// repo.Config.Set("test.boolsetting", true); + /// </para> + /// </summary> + /// <typeparam name="T">The configuration value type</typeparam> + /// <param name="key">The key parts</param> + /// <param name="value">The value</param> + public virtual void Set<T>(string key, T value) + { + Set(key, value, ConfigurationLevel.Local); + } + + /// <summary> /// Set a configuration value for a key. Keys are in the form 'section.name'. /// <para> /// For example in order to set the value for this in a .git\config file: @@ -226,7 +273,7 @@ namespace LibGit2Sharp /// <param name="key">The key parts</param> /// <param name="value">The value</param> /// <param name="level">The configuration file which should be considered as the target of this operation</param> - public virtual void Set<T>(string key, T value, ConfigurationLevel level = ConfigurationLevel.Local) + public virtual void Set<T>(string key, T value, ConfigurationLevel level) { Ensure.ArgumentNotNull(value, "value"); Ensure.ArgumentNotNullOrEmptyString(key, "key"); @@ -246,10 +293,19 @@ namespace LibGit2Sharp /// Find configuration entries matching <paramref name="regexp"/>. /// </summary> /// <param name="regexp">A regular expression.</param> + /// <returns>Matching entries.</returns> + public virtual IEnumerable<ConfigurationEntry<string>> Find(string regexp) + { + return Find(regexp, ConfigurationLevel.Local); + } + + /// <summary> + /// Find configuration entries matching <paramref name="regexp"/>. + /// </summary> + /// <param name="regexp">A regular expression.</param> /// <param name="level">The configuration file into which the key should be searched for.</param> /// <returns>Matching entries.</returns> - public virtual IEnumerable<ConfigurationEntry<string>> Find(string regexp, - ConfigurationLevel level = ConfigurationLevel.Local) + public virtual IEnumerable<ConfigurationEntry<string>> Find(string regexp, ConfigurationLevel level) { Ensure.ArgumentNotNullOrEmptyString(regexp, "regexp"); diff --git a/LibGit2Sharp/ConfigurationExtensions.cs b/LibGit2Sharp/ConfigurationExtensions.cs index 5e79a289..1ffd7159 100644 --- a/LibGit2Sharp/ConfigurationExtensions.cs +++ b/LibGit2Sharp/ConfigurationExtensions.cs @@ -69,6 +69,18 @@ namespace LibGit2Sharp } /// <summary> + /// Get a configuration value for the given key. + /// </summary> + /// <typeparam name="T">The configuration value type.</typeparam> + /// <param name="config">The configuration being worked with.</param> + /// <param name="key">The key</param> + /// <returns>The configuration value, or the default value for the selected <see typeparamref="T"/>if not found</returns> + public static T GetValueOrDefault<T>(this Configuration config, string key) + { + return ValueOrDefault(config.Get<T>(key), default(T)); + } + + /// <summary> /// Get a configuration value for the given key, /// or <paramref name="defaultValue" /> if the key is not set. /// </summary> @@ -76,28 +88,53 @@ namespace LibGit2Sharp /// <param name="config">The configuration being worked with.</param> /// <param name="key">The key</param> /// <param name="defaultValue">The default value if the key is not set.</param> - /// <returns>The configuration value, or the default.</returns> - public static T GetValueOrDefault<T>(this Configuration config, string key, T defaultValue = default(T)) + /// <returns>The configuration value, or the default value</returns> + public static T GetValueOrDefault<T>(this Configuration config, string key, T defaultValue) { return ValueOrDefault(config.Get<T>(key), defaultValue); } /// <summary> + /// Get a configuration value for the given key + /// </summary> + /// <typeparam name="T">The configuration value type.</typeparam> + /// <param name="config">The configuration being worked with.</param> + /// <param name="key">The key.</param> + /// <param name="level">The configuration file into which the key should be searched for.</param> + /// <returns>The configuration value, or the default value for <see typeparamref="T"/> if not found</returns> + public static T GetValueOrDefault<T>(this Configuration config, string key, ConfigurationLevel level) + { + return ValueOrDefault(config.Get<T>(key, level), default(T)); + } + + /// <summary> /// Get a configuration value for the given key, /// or <paramref name="defaultValue" /> if the key is not set. /// </summary> /// <typeparam name="T">The configuration value type.</typeparam> - /// <param name="config">The configuration being worked with.</param> + /// <param name="config">The configuration being worked with.</param> /// <param name="key">The key.</param> /// <param name="level">The configuration file into which the key should be searched for.</param> /// <param name="defaultValue">The selector used to generate a default value if the key is not set.</param> - /// <returns>The configuration value, or the default.</returns> - public static T GetValueOrDefault<T>(this Configuration config, string key, ConfigurationLevel level, T defaultValue = default(T)) + /// <returns>The configuration value, or the default value.</returns> + public static T GetValueOrDefault<T>(this Configuration config, string key, ConfigurationLevel level, T defaultValue) { return ValueOrDefault(config.Get<T>(key, level), defaultValue); } /// <summary> + /// Get a configuration value for the given key parts + /// </summary> + /// <typeparam name="T">The configuration value type.</typeparam> + /// <param name="config">The configuration being worked with.</param> + /// <param name="keyParts">The key parts.</param> + /// <returns>The configuration value, or the default value for<see typeparamref="T"/> if not found</returns> + public static T GetValueOrDefault<T>(this Configuration config, string[] keyParts) + { + return ValueOrDefault(config.Get<T>(keyParts), default(T)); + } + + /// <summary> /// Get a configuration value for the given key parts, /// or <paramref name="defaultValue" /> if the key is not set. /// </summary> @@ -105,13 +142,27 @@ namespace LibGit2Sharp /// <param name="config">The configuration being worked with.</param> /// <param name="keyParts">The key parts.</param> /// <param name="defaultValue">The default value if the key is not set.</param> - /// <returns>The configuration value, or the default.</returns> - public static T GetValueOrDefault<T>(this Configuration config, string[] keyParts, T defaultValue = default(T)) + /// <returns>The configuration value, or the default value.</returns> + public static T GetValueOrDefault<T>(this Configuration config, string[] keyParts, T defaultValue) { return ValueOrDefault(config.Get<T>(keyParts), defaultValue); } /// <summary> + /// Get a configuration value for the given key parts. + /// </summary> + /// <typeparam name="T">The configuration value type.</typeparam> + /// <param name="config">The configuration being worked with.</param> + /// <param name="firstKeyPart">The first key part.</param> + /// <param name="secondKeyPart">The second key part.</param> + /// <param name="thirdKeyPart">The third key part.</param> + /// <returns>The configuration value, or the default value for the selected <see typeparamref="T"/> if not found</returns> + public static T GetValueOrDefault<T>(this Configuration config, string firstKeyPart, string secondKeyPart, string thirdKeyPart) + { + return ValueOrDefault(config.Get<T>(firstKeyPart, secondKeyPart, thirdKeyPart), default(T)); + } + + /// <summary> /// Get a configuration value for the given key parts, /// or <paramref name="defaultValue" /> if the key is not set. /// </summary> @@ -122,7 +173,7 @@ namespace LibGit2Sharp /// <param name="thirdKeyPart">The third key part.</param> /// <param name="defaultValue">The default value if the key is not set.</param> /// <returns>The configuration value, or the default.</returns> - public static T GetValueOrDefault<T>(this Configuration config, string firstKeyPart, string secondKeyPart, string thirdKeyPart, T defaultValue = default(T)) + public static T GetValueOrDefault<T>(this Configuration config, string firstKeyPart, string secondKeyPart, string thirdKeyPart, T defaultValue) { return ValueOrDefault(config.Get<T>(firstKeyPart, secondKeyPart, thirdKeyPart), defaultValue); } diff --git a/LibGit2Sharp/Diff.cs b/LibGit2Sharp/Diff.cs index 126d4bec..54ad11b0 100644 --- a/LibGit2Sharp/Diff.cs +++ b/LibGit2Sharp/Diff.cs @@ -107,9 +107,20 @@ namespace LibGit2Sharp /// </summary> /// <param name="oldBlob">The <see cref="Blob"/> you want to compare from.</param> /// <param name="newBlob">The <see cref="Blob"/> you want to compare to.</param> + /// <returns>A <see cref="ContentChanges"/> containing the changes between the <paramref name="oldBlob"/> and the <paramref name="newBlob"/>.</returns> + public virtual ContentChanges Compare(Blob oldBlob, Blob newBlob) + { + return Compare(oldBlob, newBlob, null); + } + + /// <summary> + /// Show changes between two <see cref="Blob"/>s. + /// </summary> + /// <param name="oldBlob">The <see cref="Blob"/> you want to compare from.</param> + /// <param name="newBlob">The <see cref="Blob"/> you want to compare to.</param> /// <param name="compareOptions">Additional options to define comparison behavior.</param> /// <returns>A <see cref="ContentChanges"/> containing the changes between the <paramref name="oldBlob"/> and the <paramref name="newBlob"/>.</returns> - public virtual ContentChanges Compare(Blob oldBlob, Blob newBlob, CompareOptions compareOptions = null) + public virtual ContentChanges Compare(Blob oldBlob, Blob newBlob, CompareOptions compareOptions) { using (GitDiffOptions options = BuildOptions(DiffModifiers.None, compareOptions: compareOptions)) { @@ -122,6 +133,71 @@ namespace LibGit2Sharp /// </summary> /// <param name="oldTree">The <see cref="Tree"/> you want to compare from.</param> /// <param name="newTree">The <see cref="Tree"/> you want to compare to.</param> + /// <returns>A <see cref="TreeChanges"/> containing the changes between the <paramref name="oldTree"/> and the <paramref name="newTree"/>.</returns> + public virtual T Compare<T>(Tree oldTree, Tree newTree) where T : class + { + return Compare<T>(oldTree, newTree, null, null, null); + } + + /// <summary> + /// Show changes between two <see cref="Tree"/>s. + /// </summary> + /// <param name="oldTree">The <see cref="Tree"/> you want to compare from.</param> + /// <param name="newTree">The <see cref="Tree"/> you want to compare to.</param> + /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> + /// <returns>A <see cref="TreeChanges"/> containing the changes between the <paramref name="oldTree"/> and the <paramref name="newTree"/>.</returns> + public virtual T Compare<T>(Tree oldTree, Tree newTree, IEnumerable<string> paths) where T : class + { + return Compare<T>(oldTree, newTree, paths, null, null); + } + + /// <summary> + /// Show changes between two <see cref="Tree"/>s. + /// </summary> + /// <param name="oldTree">The <see cref="Tree"/> you want to compare from.</param> + /// <param name="newTree">The <see cref="Tree"/> you want to compare to.</param> + /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> + /// <param name="explicitPathsOptions"> + /// If set, the passed <paramref name="paths"/> will be treated as explicit paths. + /// Use these options to determine how unmatched explicit paths should be handled. + /// </param> + /// <returns>A <see cref="TreeChanges"/> containing the changes between the <paramref name="oldTree"/> and the <paramref name="newTree"/>.</returns> + public virtual T Compare<T>(Tree oldTree, Tree newTree, IEnumerable<string> paths, + ExplicitPathsOptions explicitPathsOptions) where T : class + { + return Compare<T>(oldTree, newTree, paths, explicitPathsOptions, null); + } + + /// <summary> + /// Show changes between two <see cref="Tree"/>s. + /// </summary> + /// <param name="oldTree">The <see cref="Tree"/> you want to compare from.</param> + /// <param name="newTree">The <see cref="Tree"/> you want to compare to.</param> + /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> + /// <param name="compareOptions">Additional options to define patch generation behavior.</param> + /// <returns>A <see cref="TreeChanges"/> containing the changes between the <paramref name="oldTree"/> and the <paramref name="newTree"/>.</returns> + public virtual T Compare<T>(Tree oldTree, Tree newTree, IEnumerable<string> paths, CompareOptions compareOptions) where T : class + { + return Compare<T>(oldTree, newTree, paths, null, compareOptions); + } + + /// <summary> + /// Show changes between two <see cref="Tree"/>s. + /// </summary> + /// <param name="oldTree">The <see cref="Tree"/> you want to compare from.</param> + /// <param name="newTree">The <see cref="Tree"/> you want to compare to.</param> + /// <param name="compareOptions">Additional options to define patch generation behavior.</param> + /// <returns>A <see cref="TreeChanges"/> containing the changes between the <paramref name="oldTree"/> and the <paramref name="newTree"/>.</returns> + public virtual T Compare<T>(Tree oldTree, Tree newTree, CompareOptions compareOptions) where T : class + { + return Compare<T>(oldTree, newTree, null, null, compareOptions); + } + + /// <summary> + /// Show changes between two <see cref="Tree"/>s. + /// </summary> + /// <param name="oldTree">The <see cref="Tree"/> you want to compare from.</param> + /// <param name="newTree">The <see cref="Tree"/> you want to compare to.</param> /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> /// <param name="explicitPathsOptions"> /// If set, the passed <paramref name="paths"/> will be treated as explicit paths. @@ -129,8 +205,8 @@ namespace LibGit2Sharp /// </param> /// <param name="compareOptions">Additional options to define patch generation behavior.</param> /// <returns>A <see cref="TreeChanges"/> containing the changes between the <paramref name="oldTree"/> and the <paramref name="newTree"/>.</returns> - public virtual T Compare<T>(Tree oldTree, Tree newTree, IEnumerable<string> paths = null, ExplicitPathsOptions explicitPathsOptions = null, - CompareOptions compareOptions = null) where T : class + public virtual T Compare<T>(Tree oldTree, Tree newTree, IEnumerable<string> paths, ExplicitPathsOptions explicitPathsOptions, + CompareOptions compareOptions) where T : class { Func<DiffSafeHandle, object> builder; @@ -173,6 +249,64 @@ namespace LibGit2Sharp /// </summary> /// <param name="oldTree">The <see cref="Tree"/> to compare from.</param> /// <param name="diffTargets">The targets to compare to.</param> + /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or + /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam> + /// <returns>A <typeparamref name="T"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns> + public virtual T Compare<T>(Tree oldTree, DiffTargets diffTargets) where T : class + { + return Compare<T>(oldTree, diffTargets, null, null, null); + } + + /// <summary> + /// Show changes between a <see cref="Tree"/> and the Index, the Working Directory, or both. + /// <para> + /// The level of diff performed can be specified by passing either a <see cref="TreeChanges"/> + /// or <see cref="Patch"/> type as the generic parameter. + /// </para> + /// </summary> + /// <param name="oldTree">The <see cref="Tree"/> to compare from.</param> + /// <param name="diffTargets">The targets to compare to.</param> + /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> + /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or + /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam> + /// <returns>A <typeparamref name="T"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns> + public virtual T Compare<T>(Tree oldTree, DiffTargets diffTargets, IEnumerable<string> paths) where T : class + { + return Compare<T>(oldTree, diffTargets, paths, null, null); + } + + /// <summary> + /// Show changes between a <see cref="Tree"/> and the Index, the Working Directory, or both. + /// <para> + /// The level of diff performed can be specified by passing either a <see cref="TreeChanges"/> + /// or <see cref="Patch"/> type as the generic parameter. + /// </para> + /// </summary> + /// <param name="oldTree">The <see cref="Tree"/> to compare from.</param> + /// <param name="diffTargets">The targets to compare to.</param> + /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> + /// <param name="explicitPathsOptions"> + /// If set, the passed <paramref name="paths"/> will be treated as explicit paths. + /// Use these options to determine how unmatched explicit paths should be handled. + /// </param> + /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or + /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam> + /// <returns>A <typeparamref name="T"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns> + public virtual T Compare<T>(Tree oldTree, DiffTargets diffTargets, IEnumerable<string> paths, + ExplicitPathsOptions explicitPathsOptions) where T : class + { + return Compare<T>(oldTree, diffTargets, paths, explicitPathsOptions, null); + } + + /// <summary> + /// Show changes between a <see cref="Tree"/> and the Index, the Working Directory, or both. + /// <para> + /// The level of diff performed can be specified by passing either a <see cref="TreeChanges"/> + /// or <see cref="Patch"/> type as the generic parameter. + /// </para> + /// </summary> + /// <param name="oldTree">The <see cref="Tree"/> to compare from.</param> + /// <param name="diffTargets">The targets to compare to.</param> /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> /// <param name="explicitPathsOptions"> /// If set, the passed <paramref name="paths"/> will be treated as explicit paths. @@ -182,8 +316,8 @@ namespace LibGit2Sharp /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam> /// <returns>A <typeparamref name="T"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns> - public virtual T Compare<T>(Tree oldTree, DiffTargets diffTargets, IEnumerable<string> paths = null, - ExplicitPathsOptions explicitPathsOptions = null, CompareOptions compareOptions = null) where T : class + public virtual T Compare<T>(Tree oldTree, DiffTargets diffTargets, IEnumerable<string> paths, + ExplicitPathsOptions explicitPathsOptions, CompareOptions compareOptions) where T : class { Func<DiffSafeHandle, object> builder; @@ -226,6 +360,76 @@ namespace LibGit2Sharp /// or <see cref="Patch"/> type as the generic parameter. /// </para> /// </summary> + /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or + /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam> + /// <returns>A <typeparamref name="T"/> containing the changes between the working directory and the index.</returns> + public virtual T Compare<T>() where T : class + { + return Compare<T>(DiffModifiers.None); + } + + /// <summary> + /// Show changes between the working directory and the index. + /// <para> + /// The level of diff performed can be specified by passing either a <see cref="TreeChanges"/> + /// or <see cref="Patch"/> type as the generic parameter. + /// </para> + /// </summary> + /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> + /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or + /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam> + /// <returns>A <typeparamref name="T"/> containing the changes between the working directory and the index.</returns> + public virtual T Compare<T>(IEnumerable<string> paths) where T : class + { + return Compare<T>(DiffModifiers.None, paths); + } + + /// <summary> + /// Show changes between the working directory and the index. + /// <para> + /// The level of diff performed can be specified by passing either a <see cref="TreeChanges"/> + /// or <see cref="Patch"/> type as the generic parameter. + /// </para> + /// </summary> + /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> + /// <param name="includeUntracked">If true, include untracked files from the working dir as additions. Otherwise ignore them.</param> + /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or + /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam> + /// <returns>A <typeparamref name="T"/> containing the changes between the working directory and the index.</returns> + public virtual T Compare<T>(IEnumerable<string> paths, bool includeUntracked) where T : class + { + return Compare<T>(includeUntracked ? DiffModifiers.IncludeUntracked : DiffModifiers.None, paths); + } + + /// <summary> + /// Show changes between the working directory and the index. + /// <para> + /// The level of diff performed can be specified by passing either a <see cref="TreeChanges"/> + /// or <see cref="Patch"/> type as the generic parameter. + /// </para> + /// </summary> + /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> + /// <param name="includeUntracked">If true, include untracked files from the working dir as additions. Otherwise ignore them.</param> + /// <param name="explicitPathsOptions"> + /// If set, the passed <paramref name="paths"/> will be treated as explicit paths. + /// Use these options to determine how unmatched explicit paths should be handled. + /// </param> + /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or + /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam> + /// <returns>A <typeparamref name="T"/> containing the changes between the working directory and the index.</returns> + public virtual T Compare<T>(IEnumerable<string> paths, bool includeUntracked, + ExplicitPathsOptions explicitPathsOptions) where T : class + { + return Compare<T>(includeUntracked ? DiffModifiers.IncludeUntracked : DiffModifiers.None, paths, explicitPathsOptions); + } + + /// <summary> + /// Show changes between the working directory and the index. + /// <para> + /// The level of diff performed can be specified by passing either a <see cref="TreeChanges"/> + /// or <see cref="Patch"/> type as the generic parameter. + /// </para> + /// </summary> /// <param name="paths">The list of paths (either files or directories) that should be compared.</param> /// <param name="includeUntracked">If true, include untracked files from the working dir as additions. Otherwise ignore them.</param> /// <param name="explicitPathsOptions"> @@ -236,8 +440,8 @@ namespace LibGit2Sharp /// <typeparam name="T">Can be either a <see cref="TreeChanges"/> if you are only interested in the list of files modified, added, ..., or /// a <see cref="Patch"/> if you want the actual patch content for the whole diff and for individual files.</typeparam> /// <returns>A <typeparamref name="T"/> containing the changes between the working directory and the index.</returns> - public virtual T Compare<T>(IEnumerable<string> paths = null, bool includeUntracked = false, ExplicitPathsOptions explicitPathsOptions = null, - CompareOptions compareOptions = null) where T : class + public virtual T Compare<T>(IEnumerable<string> paths, bool includeUntracked, ExplicitPathsOptions explicitPathsOptions, + CompareOptions compareOptions) where T : class { return Compare<T>(includeUntracked ? DiffModifiers.IncludeUntracked : DiffModifiers.None, paths, explicitPathsOptions, compareOptions); } diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index 49d80d3d..a0216f9b 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -46,9 +46,25 @@ namespace LibGit2Sharp /// </para> /// </summary> /// <param name="remote">The <see cref="Remote"/> to list from.</param> - /// <param name="credentialsProvider">The optional <see cref="Func{Credentials}"/> used to connect to remote repository.</param> /// <returns>The references in the <see cref="Remote"/> repository.</returns> - public virtual IEnumerable<DirectReference> ListReferences(Remote remote, CredentialsHandler credentialsProvider = null) + public virtual IEnumerable<DirectReference> ListReferences(Remote remote) + { + return ListReferences(remote, null); + } + + /// <summary> + /// List references in a <see cref="Remote"/> repository. + /// <para> + /// When the remote tips are ahead of the local ones, the retrieved + /// <see cref="DirectReference"/>s may point to non existing + /// <see cref="GitObject"/>s in the local repository. In that + /// case, <see cref="DirectReference.Target"/> will return <c>null</c>. + /// </para> + /// </summary> + /// <param name="remote">The <see cref="Remote"/> to list from.</param> + /// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param> + /// <returns>The references in the <see cref="Remote"/> repository.</returns> + public virtual IEnumerable<DirectReference> ListReferences(Remote remote, CredentialsHandler credentialsProvider) { Ensure.ArgumentNotNull(remote, "remote"); @@ -120,10 +136,38 @@ namespace LibGit2Sharp /// Fetch from the <see cref="Remote"/>. /// </summary> /// <param name="remote">The remote to fetch</param> + public virtual void Fetch(Remote remote) + { + Fetch(remote, (FetchOptions)null, null); + } + + /// <summary> + /// Fetch from the <see cref="Remote"/>. + /// </summary> + /// <param name="remote">The remote to fetch</param> + /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> + public virtual void Fetch(Remote remote, FetchOptions options) + { + Fetch(remote, options, null); + } + + /// <summary> + /// Fetch from the <see cref="Remote"/>. + /// </summary> + /// <param name="remote">The remote to fetch</param> + /// <param name="logMessage">Message to use when updating the reflog.</param> + public virtual void Fetch(Remote remote, string logMessage) + { + Fetch(remote, (FetchOptions)null, logMessage); + } + + /// <summary> + /// Fetch from the <see cref="Remote"/>. + /// </summary> + /// <param name="remote">The remote to fetch</param> /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> /// <param name="logMessage">Message to use when updating the reflog.</param> - public virtual void Fetch(Remote remote, FetchOptions options = null, - string logMessage = null) + public virtual void Fetch(Remote remote, FetchOptions options, string logMessage) { Ensure.ArgumentNotNull(remote, "remote"); @@ -138,10 +182,41 @@ namespace LibGit2Sharp /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="refspecs">Refspecs to use, replacing the remote's fetch refspecs</param> + public virtual void Fetch(Remote remote, IEnumerable<string> refspecs) + { + Fetch(remote, refspecs, null, null); + } + + /// <summary> + /// Fetch from the <see cref="Remote"/>, using custom refspecs. + /// </summary> + /// <param name="remote">The remote to fetch</param> + /// <param name="refspecs">Refspecs to use, replacing the remote's fetch refspecs</param> + /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> + public virtual void Fetch(Remote remote, IEnumerable<string> refspecs, FetchOptions options) + { + Fetch(remote, refspecs, options, null); + } + + /// <summary> + /// Fetch from the <see cref="Remote"/>, using custom refspecs. + /// </summary> + /// <param name="remote">The remote to fetch</param> + /// <param name="refspecs">Refspecs to use, replacing the remote's fetch refspecs</param> + /// <param name="logMessage">Message to use when updating the reflog.</param> + public virtual void Fetch(Remote remote, IEnumerable<string> refspecs, string logMessage) + { + Fetch(remote, refspecs, null, logMessage); + } + + /// <summary> + /// Fetch from the <see cref="Remote"/>, using custom refspecs. + /// </summary> + /// <param name="remote">The remote to fetch</param> + /// <param name="refspecs">Refspecs to use, replacing the remote's fetch refspecs</param> /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> /// <param name="logMessage">Message to use when updating the reflog.</param> - public virtual void Fetch(Remote remote, IEnumerable<string> refspecs, FetchOptions options = null, - string logMessage = null) + public virtual void Fetch(Remote remote, IEnumerable<string> refspecs, FetchOptions options, string logMessage) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(refspecs, "refspecs"); @@ -159,13 +234,53 @@ namespace LibGit2Sharp /// </summary> /// <param name="url">The url to fetch from</param> /// <param name="refspecs">The list of resfpecs to use</param> + public virtual void Fetch( + string url, + IEnumerable<string> refspecs) + { + Fetch(url, refspecs, null, null); + } + + /// <summary> + /// Fetch from a url with a set of fetch refspecs + /// </summary> + /// <param name="url">The url to fetch from</param> + /// <param name="refspecs">The list of resfpecs to use</param> + /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> + public virtual void Fetch( + string url, + IEnumerable<string> refspecs, + FetchOptions options) + { + Fetch(url, refspecs, options, null); + } + + /// <summary> + /// Fetch from a url with a set of fetch refspecs + /// </summary> + /// <param name="url">The url to fetch from</param> + /// <param name="refspecs">The list of resfpecs to use</param> + /// <param name="logMessage">Message to use when updating the reflog.</param> + public virtual void Fetch( + string url, + IEnumerable<string> refspecs, + string logMessage) + { + Fetch(url, refspecs, null, logMessage); + } + + /// <summary> + /// Fetch from a url with a set of fetch refspecs + /// </summary> + /// <param name="url">The url to fetch from</param> + /// <param name="refspecs">The list of resfpecs to use</param> /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> /// <param name="logMessage">Message to use when updating the reflog.</param> public virtual void Fetch( string url, IEnumerable<string> refspecs, - FetchOptions options = null, - string logMessage = null) + FetchOptions options, + string logMessage) { Ensure.ArgumentNotNull(url, "url"); Ensure.ArgumentNotNull(refspecs, "refspecs"); @@ -184,16 +299,33 @@ namespace LibGit2Sharp /// <param name="remote">The <see cref="Remote"/> to push to.</param> /// <param name="objectish">The source objectish to push.</param> /// <param name="destinationSpec">The reference to update on the remote.</param> + public virtual void Push( + Remote remote, + string objectish, + string destinationSpec) + { + Ensure.ArgumentNotNull(objectish, "objectish"); + Ensure.ArgumentNotNullOrEmptyString(destinationSpec, "destinationSpec"); + + Push(remote, string.Format(CultureInfo.InvariantCulture, + "{0}:{1}", objectish, destinationSpec)); + } + + /// <summary> + /// Push the objectish to the destination reference on the <see cref="Remote"/>. + /// </summary> + /// <param name="remote">The <see cref="Remote"/> to push to.</param> + /// <param name="objectish">The source objectish to push.</param> + /// <param name="destinationSpec">The reference to update on the remote.</param> /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param> public virtual void Push( Remote remote, string objectish, string destinationSpec, - PushOptions pushOptions = null) + PushOptions pushOptions) { - Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); - Ensure.ArgumentNotNullOrEmptyString(destinationSpec, destinationSpec); + Ensure.ArgumentNotNullOrEmptyString(destinationSpec, "destinationSpec"); Push(remote, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", objectish, destinationSpec), pushOptions); @@ -204,13 +336,25 @@ namespace LibGit2Sharp /// </summary> /// <param name="remote">The <see cref="Remote"/> to push to.</param> /// <param name="pushRefSpec">The pushRefSpec to push.</param> + public virtual void Push( + Remote remote, + string pushRefSpec) + { + Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); + + Push(remote, new[] { pushRefSpec }); + } + /// <summary> + /// Push specified reference to the <see cref="Remote"/>. + /// </summary> + /// <param name="remote">The <see cref="Remote"/> to push to.</param> + /// <param name="pushRefSpec">The pushRefSpec to push.</param> /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param> public virtual void Push( Remote remote, string pushRefSpec, - PushOptions pushOptions = null) + PushOptions pushOptions) { - Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); Push(remote, new[] { pushRefSpec }, pushOptions); @@ -221,11 +365,23 @@ namespace LibGit2Sharp /// </summary> /// <param name="remote">The <see cref="Remote"/> to push to.</param> /// <param name="pushRefSpecs">The pushRefSpecs to push.</param> + public virtual void Push( + Remote remote, + IEnumerable<string> pushRefSpecs) + { + Push(remote, pushRefSpecs, null); + } + + /// <summary> + /// Push specified references to the <see cref="Remote"/>. + /// </summary> + /// <param name="remote">The <see cref="Remote"/> to push to.</param> + /// <param name="pushRefSpecs">The pushRefSpecs to push.</param> /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param> public virtual void Push( Remote remote, IEnumerable<string> pushRefSpecs, - PushOptions pushOptions = null) + PushOptions pushOptions) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); @@ -276,7 +432,7 @@ namespace LibGit2Sharp Branch currentBranch = repository.Head; - if(!currentBranch.IsTracking) + if (!currentBranch.IsTracking) { throw new LibGit2SharpException("There is no tracking information for the current branch."); } diff --git a/LibGit2Sharp/NetworkExtensions.cs b/LibGit2Sharp/NetworkExtensions.cs index cf769c95..4efc53f0 100644 --- a/LibGit2Sharp/NetworkExtensions.cs +++ b/LibGit2Sharp/NetworkExtensions.cs @@ -14,12 +14,24 @@ namespace LibGit2Sharp /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="branch">The branch to push.</param> + /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception> + public static void Push( + this Network network, + Branch branch) + { + network.Push(new[] { branch }); + } + /// <summary> + /// Push the specified branch to its tracked branch on the remote. + /// </summary> + /// <param name="network">The <see cref="Network"/> being worked with.</param> + /// <param name="branch">The branch to push.</param> /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param> /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception> public static void Push( this Network network, Branch branch, - PushOptions pushOptions = null) + PushOptions pushOptions) { network.Push(new[] { branch }, pushOptions); } @@ -29,12 +41,25 @@ namespace LibGit2Sharp /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="branches">The branches to push.</param> + /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception> + public static void Push( + this Network network, + IEnumerable<Branch> branches) + { + network.Push(branches, null); + } + + /// <summary> + /// Push the specified branches to their tracked branches on the remote. + /// </summary> + /// <param name="network">The <see cref="Network"/> being worked with.</param> + /// <param name="branches">The branches to push.</param> /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param> /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception> public static void Push( this Network network, IEnumerable<Branch> branches, - PushOptions pushOptions = null) + PushOptions pushOptions) { var enumeratedBranches = branches as IList<Branch> ?? branches.ToList(); diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index 5ec2729d..73bd5e9b 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -75,7 +75,7 @@ namespace LibGit2Sharp /// <summary> /// Retrieves the header of a GitObject from the object database. The header contains the Size /// and Type of the object. Note that most backends do not support reading only the header - /// of an object, so the whole object will be read and then size would be returned. + /// of an object, so the whole object will be read and then size would be returned. /// </summary> /// <param name="objectId">Object Id of the queried object</param> /// <returns>GitObjectMetadata object instance containg object header information</returns> @@ -182,10 +182,38 @@ namespace LibGit2Sharp /// <para>Optionally, git filters will be applied to the content before storing it.</para> /// </summary> /// <param name="stream">The stream from which will be read the content of the blob to be created.</param> + /// <returns>The created <see cref="Blob"/>.</returns> + public virtual Blob CreateBlob(Stream stream) + { + return CreateBlob(stream, null, null); + } + + /// <summary> + /// Inserts a <see cref="Blob"/> into the object database, created from the content of a stream. + /// <para>Optionally, git filters will be applied to the content before storing it.</para> + /// </summary> + /// <param name="stream">The stream from which will be read the content of the blob to be created.</param> + /// <param name="hintpath">The hintpath is used to determine what git filters should be applied to the object before it can be placed to the object database.</param> + /// <returns>The created <see cref="Blob"/>.</returns> + public virtual Blob CreateBlob(Stream stream, string hintpath) + { + return CreateBlob(stream, hintpath, null); + } + + /// <summary> + /// Inserts a <see cref="Blob"/> into the object database, created from the content of a stream. + /// <para>Optionally, git filters will be applied to the content before storing it.</para> + /// </summary> + /// <param name="stream">The stream from which will be read the content of the blob to be created.</param> /// <param name="hintpath">The hintpath is used to determine what git filters should be applied to the object before it can be placed to the object database.</param> /// <param name="numberOfBytesToConsume">The number of bytes to consume from the stream.</param> /// <returns>The created <see cref="Blob"/>.</returns> - public virtual Blob CreateBlob(Stream stream, string hintpath = null, int? numberOfBytesToConsume = null) + public virtual Blob CreateBlob(Stream stream, string hintpath, int numberOfBytesToConsume) + { + return CreateBlob(stream, hintpath, (int?)numberOfBytesToConsume); + } + + internal Blob CreateBlob(Stream stream, string hintpath, int? numberOfBytesToConsume) { Ensure.ArgumentNotNull(stream, "stream"); @@ -295,9 +323,32 @@ namespace LibGit2Sharp /// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param> /// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param> /// <param name="prettifyMessage">True to prettify the message, or false to leave it as is.</param> - /// <param name="commentChar">Character that lines start with to be stripped if prettifyMessage is true.</param> /// <returns>The created <see cref="Commit"/>.</returns> - public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable<Commit> parents, bool prettifyMessage, char? commentChar = null) + public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable<Commit> parents, bool prettifyMessage) + { + return CreateCommit(author, committer, message, tree, parents, prettifyMessage, null); + } + + /// <summary> + /// Inserts a <see cref="Commit"/> into the object database, referencing an existing <see cref="Tree"/>. + /// <para> + /// Prettifing the message includes: + /// * Removing empty lines from the beginning and end. + /// * Removing trailing spaces from every line. + /// * Turning multiple consecutive empty lines between paragraphs into just one empty line. + /// * Ensuring the commit message ends with a newline. + /// * Removing every line starting with the <paramref name="commentChar"/>. + /// </para> + /// </summary> + /// <param name="author">The <see cref="Signature"/> of who made the change.</param> + /// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param> + /// <param name="message">The description of why a change was made to the repository.</param> + /// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param> + /// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param> + /// <param name="prettifyMessage">True to prettify the message, or false to leave it as is.</param> + /// <param name="commentChar">When non null, lines starting with this character will be stripped if prettifyMessage is true.</param> + /// <returns>The created <see cref="Commit"/>.</returns> + public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable<Commit> parents, bool prettifyMessage, char? commentChar) { Ensure.ArgumentNotNull(message, "message"); Ensure.ArgumentDoesNotContainZeroByte(message, "message"); @@ -387,11 +438,23 @@ namespace LibGit2Sharp /// string representation for a <see cref="GitObject"/>. /// </summary> /// <param name="gitObject">The <see cref="GitObject"/> which identifier should be shortened.</param> + /// <returns>A short string representation of the <see cref="ObjectId"/>.</returns> + public virtual string ShortenObjectId(GitObject gitObject) + { + var shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id); + return shortSha; + } + + /// <summary> + /// Calculates the current shortest abbreviated <see cref="ObjectId"/> + /// string representation for a <see cref="GitObject"/>. + /// </summary> + /// <param name="gitObject">The <see cref="GitObject"/> which identifier should be shortened.</param> /// <param name="minLength">Minimum length of the shortened representation.</param> /// <returns>A short string representation of the <see cref="ObjectId"/>.</returns> - public virtual string ShortenObjectId(GitObject gitObject, int? minLength = null) + public virtual string ShortenObjectId(GitObject gitObject, int minLength) { - if (minLength.HasValue && (minLength <= 0 || minLength > ObjectId.HexSize)) + if (minLength <= 0 || minLength > ObjectId.HexSize) { throw new ArgumentOutOfRangeException("minLength", minLength, string.Format("Expected value should be greater than zero and less than or equal to {0}.", ObjectId.HexSize)); @@ -399,12 +462,12 @@ namespace LibGit2Sharp string shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id); - if (minLength == null || (minLength <= shortSha.Length)) + if (minLength <= shortSha.Length) { return shortSha; } - return gitObject.Sha.Substring(0, minLength.Value); + return gitObject.Sha.Substring(0, minLength); } /// <summary> diff --git a/LibGit2Sharp/ReferenceCollection.cs b/LibGit2Sharp/ReferenceCollection.cs index e3dc68c8..ce0ed957 100644 --- a/LibGit2Sharp/ReferenceCollection.cs +++ b/LibGit2Sharp/ReferenceCollection.cs @@ -72,9 +72,21 @@ namespace LibGit2Sharp /// <param name="name">The canonical name of the reference to create.</param> /// <param name="targetId">Id of the target object.</param> /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/> when adding the <see cref="DirectReference"/></param> + /// <returns>A new <see cref="Reference"/>.</returns> + public virtual DirectReference Add(string name, ObjectId targetId, string logMessage) + { + return Add(name, targetId, logMessage, false); + } + + /// <summary> + /// Creates a direct reference with the specified name and target + /// </summary> + /// <param name="name">The canonical name of the reference to create.</param> + /// <param name="targetId">Id of the target object.</param> + /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/> when adding the <see cref="DirectReference"/></param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <returns>A new <see cref="Reference"/>.</returns> - public virtual DirectReference Add(string name, ObjectId targetId, string logMessage, bool allowOverwrite = false) + public virtual DirectReference Add(string name, ObjectId targetId, string logMessage, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(targetId, "targetId"); @@ -90,9 +102,20 @@ namespace LibGit2Sharp /// </summary> /// <param name="name">The canonical name of the reference to create.</param> /// <param name="targetId">Id of the target object.</param> + /// <returns>A new <see cref="Reference"/>.</returns> + public virtual DirectReference Add(string name, ObjectId targetId) + { + return Add(name, targetId, null, false); + } + + /// <summary> + /// Creates a direct reference with the specified name and target + /// </summary> + /// <param name="name">The canonical name of the reference to create.</param> + /// <param name="targetId">Id of the target object.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <returns>A new <see cref="Reference"/>.</returns> - public virtual DirectReference Add(string name, ObjectId targetId, bool allowOverwrite = false) + public virtual DirectReference Add(string name, ObjectId targetId, bool allowOverwrite) { return Add(name, targetId, null, allowOverwrite); } @@ -103,9 +126,21 @@ namespace LibGit2Sharp /// <param name="name">The canonical name of the reference to create.</param> /// <param name="targetRef">The target reference.</param> /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/> when adding the <see cref="SymbolicReference"/></param> + /// <returns>A new <see cref="Reference"/>.</returns> + public virtual SymbolicReference Add(string name, Reference targetRef, string logMessage) + { + return Add(name, targetRef, logMessage, false); + } + + /// <summary> + /// Creates a symbolic reference with the specified name and target + /// </summary> + /// <param name="name">The canonical name of the reference to create.</param> + /// <param name="targetRef">The target reference.</param> + /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/> when adding the <see cref="SymbolicReference"/></param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <returns>A new <see cref="Reference"/>.</returns> - public virtual SymbolicReference Add(string name, Reference targetRef, string logMessage, bool allowOverwrite = false) + public virtual SymbolicReference Add(string name, Reference targetRef, string logMessage, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(targetRef, "targetRef"); @@ -122,9 +157,20 @@ namespace LibGit2Sharp /// </summary> /// <param name="name">The canonical name of the reference to create.</param> /// <param name="targetRef">The target reference.</param> + /// <returns>A new <see cref="Reference"/>.</returns> + public virtual SymbolicReference Add(string name, Reference targetRef) + { + return Add(name, targetRef, null, false); + } + + /// <summary> + /// Creates a symbolic reference with the specified name and target + /// </summary> + /// <param name="name">The canonical name of the reference to create.</param> + /// <param name="targetRef">The target reference.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <returns>A new <see cref="Reference"/>.</returns> - public virtual SymbolicReference Add(string name, Reference targetRef, bool allowOverwrite = false) + public virtual SymbolicReference Add(string name, Reference targetRef, bool allowOverwrite) { return Add(name, targetRef, null, allowOverwrite); } @@ -146,9 +192,21 @@ namespace LibGit2Sharp /// <param name="reference">The reference to rename.</param> /// <param name="newName">The new canonical name.</param> /// <param name="logMessage">Message added to the reflog.</param> + /// <returns>A new <see cref="Reference"/>.</returns> + public virtual Reference Rename(Reference reference, string newName, string logMessage) + { + return Rename(reference, newName, logMessage, false); + } + + /// <summary> + /// Rename an existing reference with a new name, and update the reflog + /// </summary> + /// <param name="reference">The reference to rename.</param> + /// <param name="newName">The new canonical name.</param> + /// <param name="logMessage">Message added to the reflog.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <returns>A new <see cref="Reference"/>.</returns> - public virtual Reference Rename(Reference reference, string newName, string logMessage = null, bool allowOverwrite = false) + public virtual Reference Rename(Reference reference, string newName, string logMessage, bool allowOverwrite) { Ensure.ArgumentNotNull(reference, "reference"); Ensure.ArgumentNotNullOrEmptyString(newName, "newName"); @@ -171,9 +229,20 @@ namespace LibGit2Sharp /// </summary> /// <param name="reference">The reference to rename.</param> /// <param name="newName">The new canonical name.</param> + /// <returns>A new <see cref="Reference"/>.</returns> + public virtual Reference Rename(Reference reference, string newName) + { + return Rename(reference, newName, null, false); + } + + /// <summary> + /// Rename an existing reference with a new name + /// </summary> + /// <param name="reference">The reference to rename.</param> + /// <param name="newName">The new canonical name.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <returns>A new <see cref="Reference"/>.</returns> - public virtual Reference Rename(Reference reference, string newName, bool allowOverwrite = false) + public virtual Reference Rename(Reference reference, string newName, bool allowOverwrite) { return Rename(reference, newName, null, allowOverwrite); } diff --git a/LibGit2Sharp/ReferenceCollectionExtensions.cs b/LibGit2Sharp/ReferenceCollectionExtensions.cs index 423397cc..5fb2f6dd 100644 --- a/LibGit2Sharp/ReferenceCollectionExtensions.cs +++ b/LibGit2Sharp/ReferenceCollectionExtensions.cs @@ -39,9 +39,23 @@ namespace LibGit2Sharp /// <param name="name">The name of the reference to create.</param> /// <param name="canonicalRefNameOrObjectish">The target which can be either the canonical name of a reference or a revparse spec.</param> /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/> when adding the <see cref="Reference"/></param> + /// <returns>A new <see cref="Reference"/>.</returns> + public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, + string logMessage) + { + return refsColl.Add(name, canonicalRefNameOrObjectish, logMessage, false); + } + + /// <summary> + /// Creates a direct or symbolic reference with the specified name and target + /// </summary> + /// <param name="refsColl">The <see cref="ReferenceCollection"/> being worked with.</param> + /// <param name="name">The name of the reference to create.</param> + /// <param name="canonicalRefNameOrObjectish">The target which can be either the canonical name of a reference or a revparse spec.</param> + /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/> when adding the <see cref="Reference"/></param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <returns>A new <see cref="Reference"/>.</returns> - public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, string logMessage, bool allowOverwrite = false) + public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, string logMessage, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(canonicalRefNameOrObjectish, "canonicalRefNameOrObjectish"); @@ -77,6 +91,19 @@ namespace LibGit2Sharp return refsColl.Add(name, gitObject.Id, logMessage, allowOverwrite); } + + /// <summary> + /// Creates a direct or symbolic reference with the specified name and target + /// </summary> + /// <param name="refsColl">The <see cref="ReferenceCollection"/> being worked with.</param> + /// <param name="name">The name of the reference to create.</param> + /// <param name="canonicalRefNameOrObjectish">The target which can be either the canonical name of a reference or a revparse spec.</param> + /// <returns>A new <see cref="Reference"/>.</returns> + public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish) + { + return Add(refsColl, name, canonicalRefNameOrObjectish, null, false); + } + /// <summary> /// Creates a direct or symbolic reference with the specified name and target /// </summary> @@ -85,7 +112,7 @@ namespace LibGit2Sharp /// <param name="canonicalRefNameOrObjectish">The target which can be either the canonical name of a reference or a revparse spec.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <returns>A new <see cref="Reference"/>.</returns> - public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, bool allowOverwrite = false) + public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, bool allowOverwrite) { return Add(refsColl, name, canonicalRefNameOrObjectish, null, allowOverwrite); } @@ -127,12 +154,52 @@ namespace LibGit2Sharp /// </summary> /// <param name="currentName">The canonical name of the reference to rename.</param> /// <param name="newName">The new canonical name.</param> + /// <param name="refsColl">The <see cref="ReferenceCollection"/> being worked with.</param> + /// <returns>A new <see cref="Reference"/>.</returns> + public static Reference Rename(this ReferenceCollection refsColl, string currentName, string newName) + { + return refsColl.Rename(currentName, newName, null, false); + } + + /// <summary> + /// Rename an existing reference with a new name + /// </summary> + /// <param name="currentName">The canonical name of the reference to rename.</param> + /// <param name="newName">The new canonical name.</param> + /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> + /// <param name="refsColl">The <see cref="ReferenceCollection"/> being worked with.</param> + /// <returns>A new <see cref="Reference"/>.</returns> + public static Reference Rename(this ReferenceCollection refsColl, string currentName, string newName, + bool allowOverwrite) + { + return refsColl.Rename(currentName, newName, null, allowOverwrite); + } + + /// <summary> + /// Rename an existing reference with a new name + /// </summary> + /// <param name="currentName">The canonical name of the reference to rename.</param> + /// <param name="newName">The new canonical name.</param> + /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/></param> + /// <param name="refsColl">The <see cref="ReferenceCollection"/> being worked with.</param> + /// <returns>A new <see cref="Reference"/>.</returns> + public static Reference Rename(this ReferenceCollection refsColl, string currentName, string newName, + string logMessage) + { + return refsColl.Rename(currentName, newName, logMessage, false); + } + + /// <summary> + /// Rename an existing reference with a new name + /// </summary> + /// <param name="currentName">The canonical name of the reference to rename.</param> + /// <param name="newName">The new canonical name.</param> /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/></param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <param name="refsColl">The <see cref="ReferenceCollection"/> being worked with.</param> /// <returns>A new <see cref="Reference"/>.</returns> public static Reference Rename(this ReferenceCollection refsColl, string currentName, string newName, - string logMessage = null, bool allowOverwrite = false) + string logMessage, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName"); diff --git a/LibGit2Sharp/RemoteCollection.cs b/LibGit2Sharp/RemoteCollection.cs index b0eb584a..d504ca3c 100644 --- a/LibGit2Sharp/RemoteCollection.cs +++ b/LibGit2Sharp/RemoteCollection.cs @@ -145,9 +145,20 @@ namespace LibGit2Sharp /// </summary> /// <param name="name">The current remote name.</param> /// <param name="newName">The new name the existing remote should bear.</param> + /// <returns>A new <see cref="Remote"/>.</returns> + public virtual Remote Rename(string name, string newName) + { + return Rename(name, newName, null); + } + + /// <summary> + /// Renames an existing <see cref="Remote"/>. + /// </summary> + /// <param name="name">The current remote name.</param> + /// <param name="newName">The new name the existing remote should bear.</param> /// <param name="callback">The callback to be used when problems with renaming occur. (e.g. non-default fetch refspecs)</param> /// <returns>A new <see cref="Remote"/>.</returns> - public virtual Remote Rename(string name, string newName, RemoteRenameFailureHandler callback = null) + public virtual Remote Rename(string name, string newName, RemoteRenameFailureHandler callback) { Ensure.ArgumentNotNull(name, "name"); Ensure.ArgumentNotNull(newName, "newName"); diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index f7c3b537..5d08d133 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -37,7 +37,18 @@ namespace LibGit2Sharp private readonly Lazy<PathCase> pathCase; /// <summary> - /// Initializes a new instance of the <see cref="Repository"/> class, providing ooptional behavioral overrides through <paramref name="options"/> parameter. + /// Initializes a new instance of the <see cref="Repository"/> class. + /// <para>For a standard repository, <paramref name="path"/> should either point to the ".git" folder or to the working directory. For a bare repository, <paramref name="path"/> should directly point to the repository folder.</para> + /// </summary> + /// <param name="path"> + /// The path to the git repository to open, can be either the path to the git directory (for non-bare repositories this + /// would be the ".git" folder inside the working directory) or the path to the working directory. + /// </param> + public Repository(string path) : this(path, null) + { } + + /// <summary> + /// Initializes a new instance of the <see cref="Repository"/> class, providing optional behavioral overrides through <paramref name="options"/> parameter. /// <para>For a standard repository, <paramref name="path"/> should either point to the ".git" folder or to the working directory. For a bare repository, <paramref name="path"/> should directly point to the repository folder.</para> /// </summary> /// <param name="path"> @@ -47,7 +58,7 @@ namespace LibGit2Sharp /// <param name="options"> /// Overrides to the way a repository is opened. /// </param> - public Repository(string path, RepositoryOptions options = null) + public Repository(string path, RepositoryOptions options) { Ensure.ArgumentNotNullOrEmptyString(path, "path"); @@ -369,9 +380,19 @@ namespace LibGit2Sharp /// Initialize a repository at the specified <paramref name="path"/>. /// </summary> /// <param name="path">The path to the working folder when initializing a standard ".git" repository. Otherwise, when initializing a bare repository, the path to the expected location of this later.</param> + /// <returns>The path to the created repository.</returns> + public static string Init(string path) + { + return Init(path, false); + } + + /// <summary> + /// Initialize a repository at the specified <paramref name="path"/>. + /// </summary> + /// <param name="path">The path to the working folder when initializing a standard ".git" repository. Otherwise, when initializing a bare repository, the path to the expected location of this later.</param> /// <param name="isBare">true to initialize a bare repository. False otherwise, to initialize a standard ".git" repository.</param> /// <returns>The path to the created repository.</returns> - public static string Init(string path, bool isBare = false) + public static string Init(string path, bool isBare) { Ensure.ArgumentNotNullOrEmptyString(path, "path"); @@ -543,6 +564,24 @@ namespace LibGit2Sharp } /// <summary> + /// Clone using default options. + /// </summary> + /// <exception cref="RecurseSubmodulesException">This exception is thrown when there + /// is an error is encountered while recursively cloning submodules. The inner exception + /// will contain the original exception. The initially cloned repository would + /// be reported through the <see cref="RecurseSubmodulesException.InitialRepositoryPath"/> + /// property.</exception>" + /// <exception cref="UserCancelledException">Exception thrown when the cancelling + /// the clone of the initial repository.</exception>" + /// <param name="sourceUrl">URI for the remote repository</param> + /// <param name="workdirPath">Local path to clone into</param> + /// <returns>The path to the created repository.</returns> + public static string Clone(string sourceUrl, string workdirPath) + { + return Clone(sourceUrl, workdirPath, null); + } + + /// <summary> /// Clone with specified options. /// </summary> /// <exception cref="RecurseSubmodulesException">This exception is thrown when there @@ -557,7 +596,7 @@ namespace LibGit2Sharp /// <param name="options"><see cref="CloneOptions"/> controlling clone behavior</param> /// <returns>The path to the created repository.</returns> public static string Clone(string sourceUrl, string workdirPath, - CloneOptions options = null) + CloneOptions options) { Ensure.ArgumentNotNull(sourceUrl, "sourceUrl"); Ensure.ArgumentNotNull(workdirPath, "workdirPath"); diff --git a/LibGit2Sharp/RepositoryExtensions.cs b/LibGit2Sharp/RepositoryExtensions.cs index 7e37ef2f..f54d3ed8 100644 --- a/LibGit2Sharp/RepositoryExtensions.cs +++ b/LibGit2Sharp/RepositoryExtensions.cs @@ -152,13 +152,24 @@ namespace LibGit2Sharp } /// <summary> - /// Sets the current <see cref="Repository.Head"/> to the specified commit and optionally resets the <see cref="Index"/> and + /// Sets the current <see cref="Repository.Head"/> and resets the <see cref="Index"/> and + /// the content of the working tree to match. + /// </summary> + /// <param name="repository">The <see cref="Repository"/> being worked with.</param> + /// <param name="resetMode">Flavor of reset operation to perform.</param> + public static void Reset(this IRepository repository, ResetMode resetMode) + { + repository.Reset(resetMode, "HEAD"); + } + + /// <summary> + /// Sets the current <see cref="Repository.Head"/> to the specified commitish and optionally resets the <see cref="Index"/> and /// the content of the working tree to match. /// </summary> /// <param name="repository">The <see cref="Repository"/> being worked with.</param> /// <param name="resetMode">Flavor of reset operation to perform.</param> /// <param name="committish">A revparse spec for the target commit object.</param> - public static void Reset(this IRepository repository, ResetMode resetMode, string committish = "HEAD") + public static void Reset(this IRepository repository, ResetMode resetMode, string committish) { Ensure.ArgumentNotNullOrEmptyString(committish, "committish"); @@ -207,9 +218,23 @@ namespace LibGit2Sharp /// </summary> /// <param name="repository">The <see cref="Repository"/> being worked with.</param> /// <param name="message">The description of why a change was made to the repository.</param> + /// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns> + public static Commit Commit(this IRepository repository, string message) + { + return repository.Commit(message, (CommitOptions)null); + } + + /// <summary> + /// Stores the content of the <see cref="Repository.Index"/> as a new <see cref="LibGit2Sharp.Commit"/> into the repository. + /// The tip of the <see cref="Repository.Head"/> will be used as the parent of this new Commit. + /// Once the commit is created, the <see cref="Repository.Head"/> will move forward to point at it. + /// <para>Both the Author and Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable.</para> + /// </summary> + /// <param name="repository">The <see cref="Repository"/> being worked with.</param> + /// <param name="message">The description of why a change was made to the repository.</param> /// <param name="options">The <see cref="CommitOptions"/> that specify the commit behavior.</param> /// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns> - public static Commit Commit(this IRepository repository, string message, CommitOptions options = null) + public static Commit Commit(this IRepository repository, string message, CommitOptions options) { Signature author = repository.Config.BuildSignature(DateTimeOffset.Now, true); @@ -225,9 +250,25 @@ namespace LibGit2Sharp /// <param name="repository">The <see cref="Repository"/> being worked with.</param> /// <param name="author">The <see cref="Signature"/> of who made the change.</param> /// <param name="message">The description of why a change was made to the repository.</param> + /// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns> + public static Commit Commit(this IRepository repository, string message, Signature author) + { + return repository.Commit(message, author, (CommitOptions)null); + } + + + /// <summary> + /// Stores the content of the <see cref="Repository.Index"/> as a new <see cref="LibGit2Sharp.Commit"/> into the repository. + /// The tip of the <see cref="Repository.Head"/> will be used as the parent of this new Commit. + /// Once the commit is created, the <see cref="Repository.Head"/> will move forward to point at it. + /// <para>The Committer will be guessed from the Git configuration. An exception will be raised if no configuration is reachable.</para> + /// </summary> + /// <param name="repository">The <see cref="Repository"/> being worked with.</param> + /// <param name="author">The <see cref="Signature"/> of who made the change.</param> + /// <param name="message">The description of why a change was made to the repository.</param> /// <param name="options">The <see cref="CommitOptions"/> that specify the commit behavior.</param> /// <returns>The generated <see cref="LibGit2Sharp.Commit"/>.</returns> - public static Commit Commit(this IRepository repository, string message, Signature author, CommitOptions options = null) + public static Commit Commit(this IRepository repository, string message, Signature author, CommitOptions options) { Signature committer = repository.Config.BuildSignature(DateTimeOffset.Now, true); @@ -239,8 +280,18 @@ namespace LibGit2Sharp /// </summary> /// <param name="repository">The <see cref="Repository"/> being worked with.</param> /// <param name="remoteName">The name of the <see cref="Remote"/> to fetch from.</param> + public static void Fetch(this IRepository repository, string remoteName) + { + repository.Fetch(remoteName, null); + } + + /// <summary> + /// Fetch from the specified remote. + /// </summary> + /// <param name="repository">The <see cref="Repository"/> being worked with.</param> + /// <param name="remoteName">The name of the <see cref="Remote"/> to fetch from.</param> /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> - public static void Fetch(this IRepository repository, string remoteName, FetchOptions options = null) + public static void Fetch(this IRepository repository, string remoteName, FetchOptions options) { Ensure.ArgumentNotNull(repository, "repository"); Ensure.ArgumentNotNullOrEmptyString(remoteName, "remoteName"); diff --git a/LibGit2Sharp/StashCollection.cs b/LibGit2Sharp/StashCollection.cs index ffe137a5..1bc509a2 100644 --- a/LibGit2Sharp/StashCollection.cs +++ b/LibGit2Sharp/StashCollection.cs @@ -80,10 +80,41 @@ namespace LibGit2Sharp /// Creates a stash with the specified message. /// </summary> /// <param name="stasher">The <see cref="Signature"/> of the user who stashes </param> + /// <returns>the newly created <see cref="Stash"/></returns> + public virtual Stash Add(Signature stasher) + { + return Add(stasher, null, StashModifiers.Default); + } + /// <summary> + /// Creates a stash with the specified message. + /// </summary> + /// <param name="stasher">The <see cref="Signature"/> of the user who stashes </param> + /// <param name="options">A combination of <see cref="StashModifiers"/> flags</param> + /// <returns>the newly created <see cref="Stash"/></returns> + public virtual Stash Add(Signature stasher, StashModifiers options) + { + return Add(stasher, null, options); + } + + /// <summary> + /// Creates a stash with the specified message. + /// </summary> + /// <param name="stasher">The <see cref="Signature"/> of the user who stashes </param> + /// <param name="message">The message of the stash.</param> + /// <returns>the newly created <see cref="Stash"/></returns> + public virtual Stash Add(Signature stasher, string message) + { + return Add(stasher, message, StashModifiers.Default); + } + + /// <summary> + /// Creates a stash with the specified message. + /// </summary> + /// <param name="stasher">The <see cref="Signature"/> of the user who stashes </param> /// <param name="message">The message of the stash.</param> /// <param name="options">A combination of <see cref="StashModifiers"/> flags</param> /// <returns>the newly created <see cref="Stash"/></returns> - public virtual Stash Add(Signature stasher, string message = null, StashModifiers options = StashModifiers.Default) + public virtual Stash Add(Signature stasher, string message, StashModifiers options) { Ensure.ArgumentNotNull(stasher, "stasher"); diff --git a/LibGit2Sharp/TagCollection.cs b/LibGit2Sharp/TagCollection.cs index 04c42609..603ab66d 100644 --- a/LibGit2Sharp/TagCollection.cs +++ b/LibGit2Sharp/TagCollection.cs @@ -76,9 +76,22 @@ namespace LibGit2Sharp /// <param name="target">The target <see cref="GitObject"/>.</param> /// <param name="tagger">The tagger.</param> /// <param name="message">The message.</param> + /// <returns>The added <see cref="Tag"/>.</returns> + public virtual Tag Add(string name, GitObject target, Signature tagger, string message) + { + return Add(name, target, tagger, message, false); + } + + /// <summary> + /// Creates an annotated tag with the specified name. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="target">The target <see cref="GitObject"/>.</param> + /// <param name="tagger">The tagger.</param> + /// <param name="message">The message.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param> /// <returns>The added <see cref="Tag"/>.</returns> - public virtual Tag Add(string name, GitObject target, Signature tagger, string message, bool allowOverwrite = false) + public virtual Tag Add(string name, GitObject target, Signature tagger, string message, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(target, "target"); @@ -97,9 +110,20 @@ namespace LibGit2Sharp /// </summary> /// <param name="name">The name.</param> /// <param name="target">The target <see cref="GitObject"/>.</param> + /// <returns>The added <see cref="Tag"/>.</returns> + public virtual Tag Add(string name, GitObject target) + { + return Add(name, target, false); + } + + /// <summary> + /// Creates a lightweight tag with the specified name. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="target">The target <see cref="GitObject"/>.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param> /// <returns>The added <see cref="Tag"/>.</returns> - public virtual Tag Add(string name, GitObject target, bool allowOverwrite = false) + public virtual Tag Add(string name, GitObject target, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(target, "target"); diff --git a/LibGit2Sharp/TagCollectionExtensions.cs b/LibGit2Sharp/TagCollectionExtensions.cs index f976e65e..20ad5305 100644 --- a/LibGit2Sharp/TagCollectionExtensions.cs +++ b/LibGit2Sharp/TagCollectionExtensions.cs @@ -14,9 +14,22 @@ namespace LibGit2Sharp /// <param name="objectish">Revparse spec for the target object.</param> /// <param name="tagger">The tagger.</param> /// <param name="message">The message.</param> + /// <param name="tags">The <see cref="TagCollection"/> being worked with.</param> + public static Tag Add(this TagCollection tags, string name, string objectish, Signature tagger, string message) + { + return tags.Add(name, objectish, tagger, message, false); + } + + /// <summary> + /// Creates an annotated tag with the specified name. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="objectish">Revparse spec for the target object.</param> + /// <param name="tagger">The tagger.</param> + /// <param name="message">The message.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param> /// <param name="tags">The <see cref="TagCollection"/> being worked with.</param> - public static Tag Add(this TagCollection tags, string name, string objectish, Signature tagger, string message, bool allowOverwrite = false) + public static Tag Add(this TagCollection tags, string name, string objectish, Signature tagger, string message, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(objectish, "target"); @@ -30,9 +43,20 @@ namespace LibGit2Sharp /// </summary> /// <param name="name">The name.</param> /// <param name="objectish">Revparse spec for the target object.</param> + /// <param name="tags">The <see cref="TagCollection"/> being worked with.</param> + public static Tag Add(this TagCollection tags, string name, string objectish) + { + return tags.Add(name, objectish, false); + } + + /// <summary> + /// Creates a lightweight tag with the specified name. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="objectish">Revparse spec for the target object.</param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param> /// <param name="tags">The <see cref="TagCollection"/> being worked with.</param> - public static Tag Add(this TagCollection tags, string name, string objectish, bool allowOverwrite = false) + public static Tag Add(this TagCollection tags, string name, string objectish, bool allowOverwrite) { Ensure.ArgumentNotNullOrEmptyString(objectish, "objectish"); |