Skip to content

Commit

Permalink
ScmPosition: added isClean (#543)
Browse files Browse the repository at this point in the history
* ScmPosition: added isClean

* added @input to new method getIsClean()
  • Loading branch information
mkoester committed Nov 28, 2022
1 parent 77c401f commit 0b2235f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
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;
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
}
}

0 comments on commit 0b2235f

Please sign in to comment.