Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git: recognize renamed (and other status) files #1472

Merged
merged 2 commits into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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