From aa178663583d78ffacfe3ee6e52dd7b6510ed9b7 Mon Sep 17 00:00:00 2001 From: Raphael Schweizer Date: Fri, 24 Feb 2017 20:34:45 +0100 Subject: [PATCH 1/2] Git: recognize renamed files --- src/app/FakeLib/Git/FileStatus.fs | 11 ++++++++++- src/test/Test.Git/FileStatusSpecs.cs | 18 ++++++++++++++++++ src/test/Test.Git/Test.Git.csproj | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/test/Test.Git/FileStatusSpecs.cs diff --git a/src/app/FakeLib/Git/FileStatus.fs b/src/app/FakeLib/Git/FileStatus.fs index afe5462ee02..c30a1ce0d54 100644 --- a/src/app/FakeLib/Git/FileStatus.fs +++ b/src/app/FakeLib/Git/FileStatus.fs @@ -6,16 +6,25 @@ open Fake open System open System.IO +let private (|Status|_|) expected (actualWithCode:string) = + if actualWithCode.StartsWith expected then + let success, code = Int32.TryParse(actualWithCode.Substring(expected.Length)) + if success then Some code else None + else None + /// A type which represents a file status in git. type FileStatus = | Added | Modified | Deleted +/// The file has been renamed (with 0 < similarity <= 100) +| Renamed of similarity:int with - static member Parse = function + static member Parse = function | "A" -> Added | "M" -> Modified | "D" -> Deleted + | Status "R" similarity -> Renamed similarity | s -> failwithf "Unknown file status %s" s /// Gets the changed files between the given revisions diff --git a/src/test/Test.Git/FileStatusSpecs.cs b/src/test/Test.Git/FileStatusSpecs.cs new file mode 100644 index 00000000000..8b0b4bd0547 --- /dev/null +++ b/src/test/Test.Git/FileStatusSpecs.cs @@ -0,0 +1,18 @@ +using Machine.Specifications; +using static Fake.Git.FileStatus; + +namespace Test.Git +{ + public class when_getting_file_status + { + It should_be_able_to_get_renamed_files = + () => FileStatus + .Parse.Invoke("R100") + .ShouldEqual(FileStatus.NewRenamed(100)); + + It should_be_able_to_get_probably_renamed_files = + () => FileStatus + .Parse.Invoke("R75") + .ShouldEqual(FileStatus.NewRenamed(75)); + } +} \ No newline at end of file diff --git a/src/test/Test.Git/Test.Git.csproj b/src/test/Test.Git/Test.Git.csproj index c2f13d716d2..1140814fb62 100644 --- a/src/test/Test.Git/Test.Git.csproj +++ b/src/test/Test.Git/Test.Git.csproj @@ -42,6 +42,7 @@ + From f8b186e3354fc918f8c13e24022e65a6f08b4a73 Mon Sep 17 00:00:00 2001 From: Raphael Schweizer Date: Fri, 24 Feb 2017 22:54:06 +0100 Subject: [PATCH 2/2] handle all known and expected git file status --- src/app/FakeLib/Git/FileStatus.fs | 21 +++++++++------------ src/test/Test.Git/FileStatusSpecs.cs | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/app/FakeLib/Git/FileStatus.fs b/src/app/FakeLib/Git/FileStatus.fs index c30a1ce0d54..c521cab4d25 100644 --- a/src/app/FakeLib/Git/FileStatus.fs +++ b/src/app/FakeLib/Git/FileStatus.fs @@ -6,29 +6,26 @@ open Fake open System open System.IO -let private (|Status|_|) expected (actualWithCode:string) = - if actualWithCode.StartsWith expected then - let success, code = Int32.TryParse(actualWithCode.Substring(expected.Length)) - if success then Some code else None - else None - /// A type which represents a file status in git. type FileStatus = | Added -| Modified +| Copied | Deleted -/// The file has been renamed (with 0 < similarity <= 100) -| Renamed of similarity:int +| Modified +| Renamed +| TypeChange with static member Parse = function | "A" -> Added - | "M" -> Modified + | c when c.StartsWith "C" -> Copied | "D" -> Deleted - | Status "R" similarity -> Renamed similarity + | m when m.StartsWith "M" -> Modified + | r when r.StartsWith "R" -> Renamed + | "T" -> TypeChange | s -> failwithf "Unknown file status %s" s /// Gets the changed files between the given revisions -let getChangedFiles repositoryDir revision1 revision2 = +let getChangedFiles repositoryDir revision1 revision2 = checkRevisionExists repositoryDir revision1 if revision2 <> "" then checkRevisionExists repositoryDir revision2 diff --git a/src/test/Test.Git/FileStatusSpecs.cs b/src/test/Test.Git/FileStatusSpecs.cs index 8b0b4bd0547..a0a743ec054 100644 --- a/src/test/Test.Git/FileStatusSpecs.cs +++ b/src/test/Test.Git/FileStatusSpecs.cs @@ -5,14 +5,24 @@ namespace Test.Git { public class when_getting_file_status { + It should_be_able_to_get_modified_files = + () => FileStatus + .Parse.Invoke("M") + .ShouldEqual(FileStatus.Modified); + + It should_be_able_to_get_rewritten_files = + () => FileStatus + .Parse.Invoke("M42") + .ShouldEqual(FileStatus.Modified); + It should_be_able_to_get_renamed_files = () => FileStatus .Parse.Invoke("R100") - .ShouldEqual(FileStatus.NewRenamed(100)); + .ShouldEqual(FileStatus.Renamed); It should_be_able_to_get_probably_renamed_files = () => FileStatus .Parse.Invoke("R75") - .ShouldEqual(FileStatus.NewRenamed(75)); + .ShouldEqual(FileStatus.Renamed); } } \ No newline at end of file