From d1acd4a0dc3952f875d40c5ec374780d2c5f32ed Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 30 Jun 2018 21:05:38 +0100 Subject: [PATCH] HeadWriter returns Result values --- src/main/java/net/kemitix/gitdb/impl/HeadWriter.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kemitix/gitdb/impl/HeadWriter.java b/src/main/java/net/kemitix/gitdb/impl/HeadWriter.java index 39f2107..c9d6351 100644 --- a/src/main/java/net/kemitix/gitdb/impl/HeadWriter.java +++ b/src/main/java/net/kemitix/gitdb/impl/HeadWriter.java @@ -22,11 +22,11 @@ package net.kemitix.gitdb.impl; import lombok.RequiredArgsConstructor; +import net.kemitix.mon.result.Result; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -47,16 +47,17 @@ class HeadWriter { * @param branchName the branch name * @param commitId the commit to point the branch at * @return the Ref of the new branch - * @throws IOException error writing branch head */ - Ref write(final String branchName, final ObjectId commitId) throws IOException { + Result write(final String branchName, final ObjectId commitId) { final Path branchRefPath = repository .getDirectory() .toPath() .resolve(branchName) .toAbsolutePath(); final byte[] commitIdBytes = commitId.name().getBytes(StandardCharsets.UTF_8); - Files.write(branchRefPath, commitIdBytes); - return repository.findRef(branchName); + return Result.of(() -> { + Files.write(branchRefPath, commitIdBytes); + return repository.findRef(branchName); + }); } }