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

ScmPosition: added isClean #543

Merged
merged 2 commits into from
Nov 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,28 +7,40 @@ public class ScmPosition {
private final String revision;
private final String shortRevision;
private final String branch;
private final boolean isClean;

public ScmPosition(String revision, String shortRevision, String branch) {
public ScmPosition(String revision, String shortRevision, String branch, boolean isClean) {
this.revision = revision;
this.shortRevision = shortRevision;
this.branch = branch;
this.isClean = isClean;
}

public ScmPosition(String revision, String branch) {
public ScmPosition(String revision, String shortRevision, String branch) {
this(revision, shortRevision, branch, true);
}

public ScmPosition(String revision, String branch, boolean isClean) {
this.revision = revision;
if (revision.length() > 7) {
this.shortRevision = revision.substring(0, 7);
} else {
this.shortRevision = "";
}
this.branch = branch;
this.isClean = isClean;
}

public ScmPosition(String revision, String branch) {
this(revision, branch, true);
}

@Override
public String toString() {
return "ScmPosition[revision = " + revision
+ ", shortRevision = " + shortRevision
+ ", branch = " + branch + "]";
+ ", branch = " + branch
+ ", isClean = " + isClean + "]";
}

@Input
Expand All @@ -45,4 +57,9 @@ public String getShortRevision() {
public String getBranch() {
return branch;
}

@Input
public boolean getIsClean() {
return isClean;
}
}
Expand Up @@ -280,7 +280,8 @@ public ScmPosition positionOfLastChangeIn(String path, List<String> excludeSubFo

return new ScmPosition(
lastCommit.getName(),
currentPosition.getBranch()
currentPosition.getBranch(),
currentPosition.getIsClean()
);
}

Expand Down Expand Up @@ -326,8 +327,10 @@ public ScmPosition currentPosition() {
revision = head.name();
}

boolean isClean = !checkUncommittedChanges();

String branchName = branchName();
return new ScmPosition(revision, branchName);
return new ScmPosition(revision, branchName, isClean);
} catch (IOException e) {
throw new ScmException(e);
}
Expand Down
Expand Up @@ -8,6 +8,8 @@ class ScmPositionBuilder {

private String shortRevision = 'c143976'

private boolean isClean = true

private ScmPositionBuilder() {
}

Expand All @@ -20,7 +22,7 @@ class ScmPositionBuilder {
}

ScmPosition build() {
return new ScmPosition(revision, shortRevision, branch)
return new ScmPosition(revision, shortRevision, branch, isClean)
}

ScmPositionBuilder withBranch(String branch) {
Expand All @@ -33,4 +35,9 @@ class ScmPositionBuilder {
this.shortRevision = revision.substring(0, 7)
return this
}

ScmPositionBuilder withUnclean() {
this.isClean = false
return this
}
}