Skip to content

Commit

Permalink
Add dirty flag to jar
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jan 30, 2022
1 parent a978d9b commit ae42f69
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions buildscript/src/main/java/Buildscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.fabricmc.tinyremapper.TinyRemapper;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;

Expand Down Expand Up @@ -189,18 +190,19 @@ public JavaJarDependency build() {

@Override
public Path getBuildJarPath() {
Repository repository = null;
String commitHash = "";
boolean isDirty = false;
try {
repository = Git.open(getProjectDir().toFile()).getRepository();
commitHash = repository.parseCommit(repository.resolve(Constants.HEAD).toObjectId()).getName().substring(0, 8);
repository.close();
} catch (IOException e) {
Git git = Git.open(getProjectDir().toFile());
isDirty = !git.status().call().getUncommittedChanges().isEmpty();
commitHash = git.getRepository().parseCommit(git.getRepository().resolve(Constants.HEAD).toObjectId()).getName().substring(0, 8);
git.close();
} catch (IOException | GitAPIException e) {
e.printStackTrace();
}


return getBuildLibsDir().resolve(getModId() + "-" + getVersion() + "-" + commitHash + ".jar");
return getBuildLibsDir().resolve(getModId() + "-" + getVersion() + "-" + commitHash + (isDirty ? "-dirty" : "") + ".jar");
}

@Override
Expand Down

0 comments on commit ae42f69

Please sign in to comment.