Skip to content

Commit

Permalink
Merge pull request #1472 from CaringDev/GitRename
Browse files Browse the repository at this point in the history
Git: recognize renamed (and other status) files
  • Loading branch information
forki authored Feb 28, 2017
2 parents 9297501 + f8b186e commit 9cd000f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/app/FakeLib/Git/FileStatus.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ open System.IO
/// A type which represents a file status in git.
type FileStatus =
| Added
| Modified
| Copied
| Deleted
| Modified
| Renamed
| TypeChange
with
static member Parse = function
static member Parse = function
| "A" -> Added
| "M" -> Modified
| c when c.StartsWith "C" -> Copied
| "D" -> Deleted
| 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
Expand Down
28 changes: 28 additions & 0 deletions src/test/Test.Git/FileStatusSpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Machine.Specifications;
using static Fake.Git.FileStatus;

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.Renamed);

It should_be_able_to_get_probably_renamed_files =
() => FileStatus
.Parse.Invoke("R75")
.ShouldEqual(FileStatus.Renamed);
}
}
1 change: 1 addition & 0 deletions src/test/Test.Git/Test.Git.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FileStatusSpecs.cs" />
<Compile Include="Sha1Specs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GitInformationSpec.cs" />
Expand Down

0 comments on commit 9cd000f

Please sign in to comment.