diff --git a/cli/src/main/java/org/openjdk/skara/cli/GitJCheck.java b/cli/src/main/java/org/openjdk/skara/cli/GitJCheck.java index 76dac2829..18d0df176 100644 --- a/cli/src/main/java/org/openjdk/skara/cli/GitJCheck.java +++ b/cli/src/main/java/org/openjdk/skara/cli/GitJCheck.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -325,10 +325,14 @@ else if (confFile || confWorkingTree || workingTree) { if (staged) { ranges.clear(); ranges.add(STAGED_REV); + System.out.println("When jcheck is running on staged, only the following commit checks are available: " + + JCheck.commitCheckNamesForStagedOrWorkingTree()); } if (workingTree) { ranges.clear(); ranges.add(WORKING_TREE_REV); + System.out.println("When jcheck is running on working-tree, only the following commit checks are available: " + + JCheck.commitCheckNamesForStagedOrWorkingTree()); } var isLax = getSwitch("lax", arguments); diff --git a/jcheck/src/main/java/org/openjdk/skara/jcheck/JCheck.java b/jcheck/src/main/java/org/openjdk/skara/jcheck/JCheck.java index 86c5b36ea..263ae50b1 100644 --- a/jcheck/src/main/java/org/openjdk/skara/jcheck/JCheck.java +++ b/jcheck/src/main/java/org/openjdk/skara/jcheck/JCheck.java @@ -41,6 +41,14 @@ public class JCheck { private final CommitMessageParser parser; private final String revisionRange; private final List commitChecks; + private final static List commitChecksForStagedOrWorkingTree = List.of( + new AuthorCheck(), + new CommitterCheck(), + new WhitespaceCheck(), + new ExecutableCheck(), + new SymlinkCheck(), + new BinaryCheck() + ); private final List repositoryChecks; private final List additionalConfiguration; private final JCheckConfiguration overridingConfiguration; @@ -138,7 +146,8 @@ private Iterator checkCommit(Commit commit) { } var finalCensus = census; var message = parser.parse(commit); - var enabled = conf.checks().enabled(commitChecks); + var availableChecks = (revisionRange.equals(STAGED_REV) || revisionRange.equals(WORKING_TREE_REV)) ? commitChecksForStagedOrWorkingTree : commitChecks; + var enabled = conf.checks().enabled(availableChecks); var iterator = new MapIterator<>(enabled.iterator(), c -> { log.finer("Running commit check '" + c.name() + "' for " + commit.hash().hex()); return c.check(commit, message, conf, finalCensus); @@ -311,4 +320,10 @@ public static Set checksFor(ReadOnlyRepository repository, JCheckConfigur null); return jcheck.checksForRange(); } + + public static List commitCheckNamesForStagedOrWorkingTree() { + return commitChecksForStagedOrWorkingTree.stream() + .map(Check::name) + .toList(); + } } diff --git a/vcs/src/main/java/org/openjdk/skara/vcs/git/GitRepository.java b/vcs/src/main/java/org/openjdk/skara/vcs/git/GitRepository.java index 4f9f5c339..440ecd673 100644 --- a/vcs/src/main/java/org/openjdk/skara/vcs/git/GitRepository.java +++ b/vcs/src/main/java/org/openjdk/skara/vcs/git/GitRepository.java @@ -1716,7 +1716,7 @@ public Optional> stagedFileContents(Path path) { public Commit staged() throws IOException { var author = new Author(username().orElse("jcheck"), email().orElse("jcheck@none.none")); var commitMetaData = new CommitMetadata(new Hash("staged"), List.of(head()), author, ZonedDateTime.now(), - author, ZonedDateTime.now(), List.of("")); + author, ZonedDateTime.now(), List.of("Fake commit message for staged")); return new Commit(commitMetaData, List.of(diffStaged())); } @@ -1727,7 +1727,7 @@ public Commit staged() throws IOException { public Commit workingTree() throws IOException { var author = new Author(username().orElse("jcheck"), email().orElse("jcheck@none.none")); var commitMetaData = new CommitMetadata(new Hash("working-tree"), List.of(head()), author, ZonedDateTime.now(), - author, ZonedDateTime.now(), List.of("")); + author, ZonedDateTime.now(), List.of("Fake commit message for working-tree")); return new Commit(commitMetaData, List.of(diff(head()))); }