Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private List<String> tags() throws IOException {
}

private boolean clean() throws GitAPIException {
return GitUtil.status(repository).isClean();
return !GitUtil.status(repository).hasUncommittedChanges();
}

private GitDescription describe() throws IOException {
Expand Down
34 changes: 31 additions & 3 deletions src/test/java/me/qoomon/gitversioning/commons/GitUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
Expand All @@ -34,11 +35,11 @@ void status_clean() throws GitAPIException {
Status status = GitUtil.status(git.getRepository());

// then
assertThat(status.isClean()).isTrue();
assertThat(status.hasUncommittedChanges()).isFalse();
}

@Test
void status_dirty() throws GitAPIException, IOException {
void status_clean_untrackedFile() throws GitAPIException, IOException {

// given
Git git = Git.init().setInitialBranch(MASTER).setDirectory(tempDir.toFile()).call();
Expand All @@ -50,7 +51,34 @@ void status_dirty() throws GitAPIException, IOException {
Status status = GitUtil.status(git.getRepository());

// then
assertThat(status.isClean()).isFalse();
assertThat(status.getUntracked()).contains("README.md");
assertThat(status.hasUncommittedChanges()).isFalse();
}

@Test
void status_dirty_modifiedFile() throws GitAPIException, IOException {

// given
Git git = Git.init().setInitialBranch(MASTER).setDirectory(tempDir.toFile()).call();

File dummyFile = new File(tempDir.toFile(), "README.md");
boolean dummyFileCreated = dummyFile.createNewFile();
assertThat(dummyFileCreated).isTrue();

git.add().addFilepattern("README.md").call();
git.commit().setMessage("initial commit").setAllowEmpty(true).call();

try (FileWriter writer = new FileWriter(dummyFile)) {
writer.write("Hello World!");
writer.flush();
}

// when
Status status = GitUtil.status(git.getRepository());

// then
assertThat(status.getModified()).contains("README.md");
assertThat(status.hasUncommittedChanges()).isTrue();
}

@Test
Expand Down