com.rimerosolutions.ant.git.tasks.InitTask Maven / Gradle / Ivy
/*
* Copyright 2013 Rimero Solutions
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rimerosolutions.ant.git.tasks;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import com.rimerosolutions.ant.git.AbstractGitTask;
import com.rimerosolutions.ant.git.GitBuildException;
/**
* Initialize a Git repository.
*
* {@code
*
*
*
*
*
* }
*
*
*
*
* @author Yves Zoundi
*/
public class InitTask extends AbstractGitTask {
private static final String TASK_NAME = "git-init";
private static final String MESSAGE_INIT_FAILED = "Could not initialize repository.";
private boolean bare = false;
@Override
public String getName() {
return TASK_NAME;
}
/**
* Whether the repository is bare or not
*
* @antdoc.notrequired
* @param bare (Default false)
*/
public void setBare(boolean bare) {
this.bare = bare;
}
@Override
public void execute() {
try {
Git git = Git.init().
setBare(bare).
setDirectory(getDirectory()).
call();
git.getRepository().close();
} catch (GitAPIException e) {
throw new GitBuildException(MESSAGE_INIT_FAILED, e);
}
}
}