Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Implemented --autocrlf option for init, clone and quick clone #246

Merged
merged 2 commits into from

3 participants

@patthoyts

This solves with issue #220 by allowing all the repository creating commands to set the autocrlf option
when creating the git config. Added some tests to ensure the interface defaults to false and only allows true, false or auto.

patthoyts added some commits
@patthoyts patthoyts Added option to set core.autocrlf for init and clone.
This implements the suggestion in issue #220 and leaves the default as
false but permits true or auto but not any other values.

Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
7cab876
@patthoyts patthoyts Created unit tests for the --autocrlf option to init and clone.
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
bb1bfd4
@spraints spraints merged commit 65fb2da into git-tfs:master
@spraints
Owner

:metal: thanks!

@sc68cal

nice!

@thomaswurtz thomaswurtz referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 7, 2012
  1. @patthoyts

    Added option to set core.autocrlf for init and clone.

    patthoyts authored
    This implements the suggestion in issue #220 and leaves the default as
    false but permits true or auto but not any other values.
    
    Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
Commits on Nov 8, 2012
  1. @patthoyts

    Created unit tests for the --autocrlf option to init and clone.

    patthoyts authored
    Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
This page is out of date. Refresh to see the latest.
View
2  GitTfs/Commands/Init.cs
@@ -81,7 +81,7 @@ private string[] BuildInitCommand()
private void GitTfsInit(string tfsUrl, string tfsRepositoryPath)
{
- gitHelper.SetConfig("core.autocrlf", "false");
+ gitHelper.SetConfig("core.autocrlf", initOptions.GitInitAutoCrlf);
gitHelper.SetConfig("core.ignorecase", "false");
globals.Repository.CreateTfsRemote(globals.RemoteId, tfsUrl, tfsRepositoryPath, remoteOptions);
}
View
15 GitTfs/Commands/InitOptions.cs
@@ -1,3 +1,4 @@
+using System;
using System.ComponentModel;
using NDesk.Options;
using Sep.Git.Tfs.Util;
@@ -7,6 +8,9 @@ namespace Sep.Git.Tfs.Commands
[StructureMapSingleton]
public class InitOptions
{
+ private const string default_autocrlf = "false";
+ public InitOptions() { GitInitAutoCrlf = default_autocrlf; }
+
public OptionSet OptionSet
{
get
@@ -17,12 +21,23 @@ public OptionSet OptionSet
v => GitInitTemplate = v },
{ "shared:", "Passed to git-init",
v => GitInitShared = v == null ? (object)true : (object)v },
+ { "autocrlf=", "Normalize line endings (default: " + default_autocrlf + ")",
+ v => GitInitAutoCrlf = (v == "") ? default_autocrlf : ValidateCrlfValue(v) },
};
}
}
+ string ValidateCrlfValue(string v)
+ {
+ string[] valid = { "false", "true", "auto" };
+ if (!Array.Exists(valid, s => v == s))
+ throw new OptionException("error: autocrlf value must be one of true, false or auto", "autocrlf");
+ return v;
+ }
+
public string GitInitTemplate { get; set; }
public object GitInitShared { get; set; }
+ public string GitInitAutoCrlf { get; set; }
}
}
View
57 GitTfsTest/Commands/InitOptionsTest.cs
@@ -0,0 +1,57 @@
+using System.IO;
+using Sep.Git.Tfs.Commands;
+using StructureMap.AutoMocking;
+using NDesk.Options;
+using Xunit;
+
+namespace Sep.Git.Tfs.Test.Commands
+{
+ public class InitOptionsTest
+ {
+ private RhinoAutoMocker<InitOptions> mocks;
+
+ public InitOptionsTest()
+ {
+ mocks = new RhinoAutoMocker<InitOptions>();
+ }
+
+ [Fact]
+ public void AutoCrlfDefault()
+ {
+ Assert.Equal("false", mocks.ClassUnderTest.GitInitAutoCrlf);
+ }
+
+ [Fact]
+ public void AutoCrlfProvideTrue()
+ {
+ string[] args = {"init", "--autocrlf=true", "http://example.com/tfs", "$/Junk"};
+ mocks.ClassUnderTest.OptionSet.Parse(args);
+ Assert.Equal("true", mocks.ClassUnderTest.GitInitAutoCrlf);
+ }
+
+ [Fact]
+ public void AutoCrlfProvideFalse()
+ {
+ string[] args = { "init", "--autocrlf=false", "http://example.com/tfs", "$/Junk" };
+ mocks.ClassUnderTest.OptionSet.Parse(args);
+ Assert.Equal("false", mocks.ClassUnderTest.GitInitAutoCrlf);
+ }
+
+ [Fact]
+ public void AutoCrlfProvideAuto()
+ {
+ string[] args = { "init", "--autocrlf=auto", "http://example.com/tfs", "$/Junk" };
+ mocks.ClassUnderTest.OptionSet.Parse(args);
+ Assert.Equal("auto", mocks.ClassUnderTest.GitInitAutoCrlf);
+ }
+
+ [Fact]
+ public void AutoCrlfProvideInvalidOption()
+ {
+ string[] args = { "init", "--autocrlf=windows", "http://example.com/tfs", "$/Junk" };
+ Assert.Throws<OptionException>(() => mocks.ClassUnderTest.OptionSet.Parse(args));
+ Assert.Equal("false", mocks.ClassUnderTest.GitInitAutoCrlf);
+ }
+
+ }
+}
View
3  GitTfsTest/GitTfsTest.csproj
@@ -85,6 +85,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="Commands\InitOptionsTest.cs" />
<Compile Include="FactExceptOnUnix.cs" />
<Compile Include="Commands\HelpTest.cs" />
<Compile Include="Commands\ShelveTest.cs" />
@@ -152,4 +153,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project>
Something went wrong with that request. Please try again.