@Override public Revision commit(CommitRequest request) throws GitException { ensureExistenceRepoRootInWorkingDirectory(); CommitCommand command = nativeGit.createCommitCommand(); GitUser committer = getLocalCommitter(); command.setCommitter(committer); try { // overrider author from .gitconfig. We may set it in previous versions. // We need to override it since committer can differ from the person who clone or init // repository. getConfig().get("user.name"); command.setAuthor(committer); } catch (GitException e) { // ignore property not found. } command.setAll(request.isAll()); command.setAmend(request.isAmend()); command.setMessage(request.getMessage()); command.setFiles(request.getFiles()); try { command.execute(); LogCommand log = nativeGit.createLogCommand(); Revision rev = log.execute().get(0); rev.setBranch(getCurrentBranch()); return rev; } catch (Exception e) { Revision revision = DtoFactory.getInstance().createDto(Revision.class); revision.setMessage(e.getMessage()); revision.setFake(true); return revision; } }
@Override public void init(InitRequest request) throws GitException { InitCommand initCommand = nativeGit.createInitCommand(); initCommand.setBare(request.isBare()); initCommand.execute(); // make initial commit. if (!request.isBare() && request.isInitCommit()) { try { nativeGit .createAddCommand() .setFilePattern(new ArrayList<>(Collections.singletonList("."))) .execute(); nativeGit .createCommitCommand() .setCommitter(getLocalCommitter()) .setMessage("init") .execute(); } catch (GitException ignored) { // if nothing to commit } } }