Skip to content

Commit

Permalink
fix: improve Git feature experience (#106)
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun authored Dec 15, 2023
1 parent 20eb45d commit 90bc5c9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ COPY . .
RUN ./mvnw -B -ntp clean package -DskipTests

FROM public.ecr.aws/docker/library/eclipse-temurin:17-jre
RUN apt-get -y update && apt-get -y install git && \
git config --global --add safe.directory /github/workspace
COPY --from=build /build/hawkeye-cli/target/hawkeye.jar /bin/hawkeye
RUN apt-get -y update && apt-get -y install git
WORKDIR /github/workspace/
ENTRYPOINT ["/bin/hawkeye"]
3 changes: 2 additions & 1 deletion Dockerfile.native
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ RUN ./mvnw -B -ntp clean package -DskipTests -Pnative \

FROM public.ecr.aws/docker/library/alpine:3.19.0
ENV LANG C.utf8
RUN apk fix && apk --no-cache --update add gcompat git && \
git config --global --add safe.directory /github/workspace
COPY --from=build /build/hawkeye-native/target/hawkeye-native /bin/
RUN apk fix && apk --no-cache --update add gcompat git
WORKDIR /github/workspace/
ENTRYPOINT ["/bin/hawkeye-native"]
37 changes: 25 additions & 12 deletions hawkeye-core/src/main/java/io/korandoru/hawkeye/core/GitHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,31 @@ public static GitHelper create(Path baseDir, GitModel config) {
try {
p = new ProcessBuilder()
.directory(baseDir.toFile())
.command("which", "git")
.command("git", "status", "--short")
.start();
} catch (IOException e) {
if (config.getCheckIgnore().isAuto()) {
return null;
if (config.getCheckIgnore().isEnable()) {
throw new Exception("Git NotFound", e);
} else {
throw new Exception("cannot perform check-ignore", e);
log.debug("checkIgnore auto is resolved to disable");
return null;
}
}

if (p.waitFor() != 0) {
if (config.getCheckIgnore().isEnable()) {
final String error = IOUtils.toString(p.getErrorStream(), StandardCharsets.UTF_8);
throw new Exception("cannot perform check-ignore: " + error);
throw new Exception("Git NotFound: " + error);
} else {
log.debug("checkIgnore=auto is resolved to disable");
return null;
}
}

if (config.getCheckIgnore().isAuto()) {
log.debug("checkIgnore=auto is resolved to enable");
}

return new GitHelper(baseDir);
}

Expand All @@ -79,14 +85,21 @@ public void filterIgnoredFiles(Collection<String> files) {
.start();

final String output;
try (final InputStream in = p.getInputStream();
final OutputStream out = p.getOutputStream()) {
IOUtils.writeLines(files, null, out, StandardCharsets.UTF_8);
out.flush();
out.close();
output = IOUtils.toString(in, StandardCharsets.UTF_8);

try (OutputStream pStdIn = p.getOutputStream()) {
try (InputStream pStdOut = p.getInputStream()) {
IOUtils.writeLines(files, null, pStdIn, StandardCharsets.UTF_8);
pStdIn.flush();
pStdIn.close();
output = IOUtils.toString(pStdOut, StandardCharsets.UTF_8);
}
}
log.debug("git check-ignore outputs {}", output);

if (p.waitFor() != 0) {
final String error = IOUtils.toString(p.getErrorStream(), StandardCharsets.UTF_8);
throw new Exception("git check-ignore failed:\n" + error);
}
log.debug("Git check-ignore output: {}", output);

final Stream<String> lines = Arrays.stream(output.split(System.lineSeparator()));
final Set<String> ignoredFiles = lines.collect(Collectors.toSet());
Expand Down
2 changes: 0 additions & 2 deletions licenserc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ filenames = ['Dockerfile.native']
inceptionYear = 2023
copyrightOwner = "Korandoru Contributors"

[git]
checkIgnore = 'enable'

0 comments on commit 90bc5c9

Please sign in to comment.