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

Make workingDir property internal and only expose the .git directory #152

Merged
merged 3 commits into from
Jan 24, 2024
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
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
}
}
Loading