Skip to content

Commit

Permalink
Add some .gitignore handling test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed May 15, 2012
1 parent 2b77adb commit ac34838
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions LibGit2Sharp.Tests/StatusFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,31 @@ public void RetrievingTheStatusOfARepositoryReturnNativeFilePaths()
}
}

[Fact]
public void RetrievingTheStatusOfAnEmptyRepositoryHonorsTheGitIgnoreDirectives()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

using (Repository repo = Repository.Init(scd.DirectoryPath))
{
string relativePath = "look-ma.txt";
string fullFilePath = Path.Combine(repo.Info.WorkingDirectory, relativePath);
File.WriteAllText(fullFilePath, "I'm going to be ignored!");

RepositoryStatus status = repo.Index.RetrieveStatus();
Assert.Equal(new[] { relativePath }, status.Untracked);

string gitignorePath = Path.Combine(repo.Info.WorkingDirectory, ".gitignore");
File.WriteAllText(gitignorePath, "*.txt" + Environment.NewLine);

RepositoryStatus newStatus = repo.Index.RetrieveStatus();
newStatus.Untracked.Single().ShouldEqual(".gitignore");

repo.Index.RetrieveStatus(relativePath).ShouldEqual(FileStatus.Ignored);
Assert.Equal(new[] { relativePath }, newStatus.Ignored);
}
}

[Fact]
public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
{
Expand All @@ -137,13 +162,79 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
string fullFilePath = Path.Combine(repo.Info.WorkingDirectory, relativePath);
File.WriteAllText(fullFilePath, "I'm going to be ignored!");

/*
* $ git status --ignored
* # On branch master
* # Your branch and 'origin/master' have diverged,
* # and have 2 and 2 different commit(s) each, respectively.
* #
* # Changes to be committed:
* # (use "git reset HEAD <file>..." to unstage)
* #
* # deleted: deleted_staged_file.txt
* # modified: modified_staged_file.txt
* # new file: new_tracked_file.txt
* #
* # Changes not staged for commit:
* # (use "git add/rm <file>..." to update what will be committed)
* # (use "git checkout -- <file>..." to discard changes in working directory)
* #
* # modified: 1/branch_file.txt
* # modified: README
* # modified: branch_file.txt
* # deleted: deleted_unstaged_file.txt
* # modified: modified_unstaged_file.txt
* # modified: new.txt
* #
* # Untracked files:
* # (use "git add <file>..." to include in what will be committed)
* #
* # 1/look-ma.txt
* # new_untracked_file.txt
*/

RepositoryStatus status = repo.Index.RetrieveStatus();

Assert.Equal(new[]{relativePath, "new_untracked_file.txt"}, status.Untracked);

string gitignorePath = Path.Combine(repo.Info.WorkingDirectory, ".gitignore");
File.WriteAllText(gitignorePath, "*.txt" + Environment.NewLine);

/*
* $ git status --ignored
* # On branch master
* # Your branch and 'origin/master' have diverged,
* # and have 2 and 2 different commit(s) each, respectively.
* #
* # Changes to be committed:
* # (use "git reset HEAD <file>..." to unstage)
* #
* # deleted: deleted_staged_file.txt
* # modified: modified_staged_file.txt
* # new file: new_tracked_file.txt
* #
* # Changes not staged for commit:
* # (use "git add/rm <file>..." to update what will be committed)
* # (use "git checkout -- <file>..." to discard changes in working directory)
* #
* # modified: 1/branch_file.txt
* # modified: README
* # modified: branch_file.txt
* # deleted: deleted_unstaged_file.txt
* # modified: modified_unstaged_file.txt
* # modified: new.txt
* #
* # Untracked files:
* # (use "git add <file>..." to include in what will be committed)
* #
* # .gitignore
* # Ignored files:
* # (use "git add -f <file>..." to include in what will be committed)
* #
* # 1/look-ma.txt
* # new_untracked_file.txt
*/

RepositoryStatus newStatus = repo.Index.RetrieveStatus();
newStatus.Untracked.Single().ShouldEqual(".gitignore");

Expand Down

0 comments on commit ac34838

Please sign in to comment.