| | |
| | | import org.eclipse.jgit.api.CloneCommand;
|
| | | import org.eclipse.jgit.api.FetchCommand;
|
| | | import org.eclipse.jgit.api.Git;
|
| | | import org.eclipse.jgit.api.ResetCommand;
|
| | | import org.eclipse.jgit.api.ResetCommand.ResetType;
|
| | | import org.eclipse.jgit.diff.DiffEntry;
|
| | | import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
| | | import org.eclipse.jgit.diff.DiffFormatter;
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Reset HEAD to the latest remote tracking commit.
|
| | | * |
| | | * @param repository
|
| | | * @param remoteRef
|
| | | * the remote tracking reference (e.g. origin/master)
|
| | | * @return Ref
|
| | | * @throws Exception
|
| | | */
|
| | | public static Ref resetHEAD(Repository repository, String remoteRef) throws Exception {
|
| | | if (!remoteRef.startsWith(Constants.R_REMOTES)) {
|
| | | remoteRef = Constants.R_REMOTES + remoteRef;
|
| | | }
|
| | | Git git = new Git(repository);
|
| | | ResetCommand reset = git.reset();
|
| | | reset.setMode(ResetType.SOFT);
|
| | | reset.setRef(remoteRef);
|
| | | Ref result = reset.call();
|
| | | return result;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Creates a bare repository.
|
| | | *
|
| | | * @param repositoriesFolder
|
| | |
| | | */
|
| | | private static List<String> getRepositoryList(String basePath, File searchFolder,
|
| | | boolean onlyBare, boolean searchSubfolders) {
|
| | | File baseFile = new File(basePath);
|
| | | List<String> list = new ArrayList<String>();
|
| | | for (File file : searchFolder.listFiles()) {
|
| | | if (file.isDirectory()) {
|
| | |
| | | continue;
|
| | | }
|
| | | // determine repository name relative to base path
|
| | | String repository = StringUtils.getRelativePath(basePath,
|
| | | file.getAbsolutePath());
|
| | | String repository = FileUtils.getRelativePath(baseFile, file);
|
| | | list.add(repository);
|
| | | } else if (searchSubfolders && file.canRead()) {
|
| | | // look for repositories in subfolders
|
| | |
| | | list.add(new PathChangeModel(diff.getOldPath(), diff.getOldPath(), 0, diff
|
| | | .getNewMode().getBits(), commit.getId().getName(), diff
|
| | | .getChangeType()));
|
| | | } else if (diff.getChangeType().equals(ChangeType.RENAME)) {
|
| | | list.add(new PathChangeModel(diff.getOldPath(), diff.getNewPath(), 0, diff
|
| | | .getNewMode().getBits(), commit.getId().getName(), diff
|
| | | .getChangeType()));
|
| | | } else {
|
| | | list.add(new PathChangeModel(diff.getNewPath(), diff.getNewPath(), 0, diff
|
| | | .getNewMode().getBits(), commit.getId().getName(), diff
|