Skip to content

Commit

Permalink
Merge pull request #152 from shipkit/magneticflux--master
Browse files Browse the repository at this point in the history
Make workingDir property internal and only expose the .git directory
  • Loading branch information
mockitoguy authored Jan 24, 2024
2 parents 948326d + 3cfe7a9 commit 1565b58
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/org/shipkit/changelog/GenerateChangelogTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,27 @@ public void setOutputFile(File outputFile) {
this.outputFile = outputFile;
}

@InputDirectory
@Internal
public File getWorkingDir() {
return workingDir;
}

@Optional
@InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
public File getGitDir() {
return provideGitDir(workingDir);
}

static File provideGitDir(File workingDir) {
if (workingDir == null) {
return null;
}

File gitDir = new File(workingDir, ".git");
return gitDir.isDirectory() ? gitDir : null;
}

public void setWorkingDir(File workingDir) {
this.workingDir = workingDir;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.shipkit.changelog

import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification

import static org.shipkit.changelog.GenerateChangelogTask.provideGitDir

class GenerateChangelogTaskTest extends Specification {

@Rule TemporaryFolder tmp = new TemporaryFolder()

def "getGitDir is safe"() {
expect:
provideGitDir(null) == null
provideGitDir(new File("missing")) == null

and:
def gitDir = tmp.newFolder(".git")
provideGitDir(gitDir.parentFile) == gitDir
}
}

0 comments on commit 1565b58

Please sign in to comment.