Java源码示例:org.eclipse.jgit.submodule.SubmoduleStatus
示例1
/**
* Obtain information about all submodules of the Git repository at the given path. Returns an empty map in case the
* repository does not include submodules. Throws exceptions in case of error.
*/
public static Map<String, SubmoduleStatus> getSubmodules(final Path localClonePath) {
if (!isValidLocalClonePath(localClonePath)) {
throw new IllegalArgumentException("invalid localClonePath: " + localClonePath);
}
try (final Git git = open(localClonePath.toFile())) {
return git.submoduleStatus().call();
} catch (Exception e) {
LOGGER.error(e.getClass().getSimpleName()
+ " while trying to obtain status of all submodules"
+ " of repository '" + localClonePath
+ "':" + e.getLocalizedMessage());
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
示例2
@Override
protected void run () throws GitException {
Repository repository = getRepository();
File workTree = repository.getWorkTree();
org.eclipse.jgit.api.SubmoduleStatusCommand cmd = new Git(repository).submoduleStatus();
for (String path : Utils.getRelativePaths(workTree, roots)) {
cmd.addPath(path);
}
try {
Map<String, SubmoduleStatus> result = cmd.call();
GitClassFactory fac = getClassFactory();
for (Map.Entry<String, SubmoduleStatus> e : result.entrySet()) {
File root = new File(workTree, e.getKey());
statuses.put(root, fac.createSubmoduleStatus(e.getValue(), root));
}
} catch (GitAPIException | JGitInternalException ex) {
throw new GitException(ex);
}
}
示例3
@Override
public void printSubmoduleStatus() {
Repository repository = null;
try {
repository = getRepository(workingDir);
Git git = new Git(repository);
SubmoduleStatusCommand submoduleStatus = git.submoduleStatus();
Map<String, SubmoduleStatus> submoduleStatusMap = submoduleStatus.call();
for (String submoduleFolder : submoduleStatusMap.keySet()) {
// print
}
} catch (Exception e) {
throw new RuntimeException("sub-module print status failed", e);
} finally {
if (repository != null) {
repository.close();
}
}
}
示例4
public static boolean updateSubmodules(Repository repo) throws GitAPIException {
SubmoduleInitCommand init = new SubmoduleInitCommand(repo);
init.call();
SubmoduleUpdateCommand update = new SubmoduleUpdateCommand(repo);
Collection<String> updated = update.call();
SubmoduleStatusCommand status = new SubmoduleStatusCommand(repo);
Map<String, SubmoduleStatus> statusResult = status.call();
return updated.size() == statusResult.size();
}
示例5
public static boolean syncSubmodules(Repository repo) throws GitAPIException {
SubmoduleSyncCommand sync = new SubmoduleSyncCommand(repo);
Map<String, String> synced = sync.call();
SubmoduleStatusCommand status = new SubmoduleStatusCommand(repo);
Map<String, SubmoduleStatus> statusResult = status.call();
return synced.size() == statusResult.size();
}
示例6
@Override
public GitSubmoduleStatus createSubmoduleStatus (SubmoduleStatus status, File folder) {
return new GitSubmoduleStatus(status, folder);
}
示例7
GitSubmoduleStatus (SubmoduleStatus delegate, File folder) {
this.delegate = delegate;
this.folder = folder;
this.statusType = parseStatus(delegate.getType());
}
示例8
public abstract GitSubmoduleStatus createSubmoduleStatus (SubmoduleStatus status, File folder);