List of usage examples for org.eclipse.jgit.lib Constants DOT_GIT_MODULES
String DOT_GIT_MODULES
To view the source code for org.eclipse.jgit.lib Constants DOT_GIT_MODULES.
Click Source Link
From source file:com.bacoder.scmtools.git.internal.CloneAndProcessDirCacheCheckout.java
License:Apache License
@Override protected boolean checkoutEntries() throws IOException { Map<String, ObjectId> updated = getUpdated(); List<String> paths = Lists.newArrayList(updated.keySet()); Collections.sort(paths);// w w w .j ava2 s.co m ObjectReader objectReader = repository.getObjectDatabase().newReader(); try { for (String path : paths) { DirCacheEntry entry = dirCache.getEntry(path); if (FileMode.GITLINK.equals(entry.getRawMode())) continue; boolean isSubmoduleConfig = path.equals(Constants.DOT_GIT_MODULES); ObjectId objectId = updated.get(path); if (isSubmoduleConfig) { ObjectLoader loader = objectReader.open(objectId); byte[] data = loader.getBytes(); submodulesConfig = data; } if (processor != null) { GitEntry gitEntry = new GitEntry(repository, objectId, pathPrefix, path); try { processor.process(gitEntry); } catch (Exception e) { throw new InternalRuntimeException(e); } } } // commit the index builder - a new index is persisted if (!getBuilder().commit()) throw new IndexWriteException(); } finally { objectReader.release(); } return true; }
From source file:com.bacoder.scmtools.git.internal.InMemorySubmoduleWalk.java
License:Apache License
@Override public SubmoduleWalk loadModulesConfig() throws IOException, ConfigInvalidException { File modulesFile = new File(repository.getWorkTree(), Constants.DOT_GIT_MODULES); FileBasedConfig config = new FileBasedConfig(modulesFile, repository.getFS()) { @Override/* w ww .java 2 s. c o m*/ protected byte[] readFully() throws IOException { return submodulesConfig; } }; config.load(); setModulesConfig(config); return this; }
From source file:com.tactfactory.harmony.utils.GitUtils.java
License:Open Source License
/** * Add a submodule to .gitmodules file.//w w w . j a va 2s .co m * @param repositoryPath Absolute path of the repository * @param submodulePath Absolute path of the submodule repository * @param submoduleUrl Url of the submodule * @throws IOException */ public static void addSubmodule(String repositoryPath, String submodulePath, String submoduleUrl) throws IOException { // Get main repository RepositoryBuilder repoBuilder = new RepositoryBuilder(); Repository repository = repoBuilder.setWorkTree(new File(repositoryPath)) .setGitDir(new File(repositoryPath + "/.git")).readEnvironment().findGitDir().build(); // Get submodule relative path String path = TactFileUtils.absoluteToRelativePath(submodulePath, repositoryPath); path = path.substring(0, path.length() - 1); // Update .gitmodules file try { FileBasedConfig modulesConfig = new FileBasedConfig( new File(repository.getWorkTree(), Constants.DOT_GIT_MODULES), repository.getFS()); modulesConfig.load(); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_PATH, path); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL, submoduleUrl); modulesConfig.save(); } catch (ConfigInvalidException e) { ConsoleUtils.displayError(e); } repository.close(); }
From source file:net.polydawn.mdm.commands.MdmAddCommand.java
License:Open Source License
public MdmExitMessage call() throws ConfigInvalidException, IOException, MdmException { assertInRepoRoot();//w w w . j ava 2s . co m // load other config (so we can error early on in case there's a problem) StoredConfig gitmodulesCfg = new FileBasedConfig(new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES), repo.getFS()); try { gitmodulesCfg.load(); } catch (ConfigInvalidException e) { throw new MdmExitInvalidConfig(Constants.DOT_GIT_MODULES); } // git's behavior of assuming relative urls should be relative to the remote origin instead of relative to the local filesystem is almost certainly not what you want. if (url.startsWith("../") || url.startsWith("./")) os.println( "hey, heads up: when you use a relative url to describe a submodule location, git assumes it's relative to the remote origin of the parent project (NOT relative to the project location on the local filesystem, which is what you might have expected). this... works, but it's not recommended because of the potential it has to surprise."); // give a look at the remote url and see what versions are physically available. List<String> versions = fetchVersions(); if (versions.size() == 0) throw new MdmExitMessage(":(", "no releases could be found at the url you gave for a releases repository -- it doesn't look like releases that mdm understands are there.\nare you sure this is the releases repo? keep in mind that the release repo and the source repo isn't the same for most projects -- check the project readme for the location of their release repo."); // if we didn't get a name argument yet, prompt for one. // note that this is *after* we tried to check that something at least exists on the far side of the url, in order to minimize bother. if (name == null) name = inputPrompt(os, "dependency name: "); File path = new File(pathLibs, name); // check for presence of other crap here already. (`git submodule add` will also do this, but it's a more pleasant user experience to check this before popping up a prompt for version name.) if (path.exists()) throw new MdmExitMessage(":'(", "there are already files at " + path + " !\nWe can't pull down a dependency there until this conflict is cleared away."); if (SubmoduleWalk.forIndex(repo).setFilter(PathFilter.create(path.getPath())).next()) throw new MdmExitMessage(":'(", "there is already a submodule in the git index at " + path + " !\nWe can't pull down a dependency there until this conflict is cleared away."); // if a specific version name was given, we'll just go straight at it; otherwise we present options interactively from the manifest of versions the remote reported. if (version == null) version = Loco.promptForVersion(os, versions); // check yourself before you wreck yourself if (!versions.contains(version)) throw new MdmExitMessage(":(", "no version labelled " + version + " available from the provided remote url."); // finally, let's actually do the submodule/dependency adding doSubmoduleConfig(gitmodulesCfg, path); gitmodulesCfg.save(); doSubmoduleFetch(path, gitmodulesCfg); // commit the changes doGitStage(path); doGitCommit(path); return new MdmExitMessage(":D", "added dependency on " + name + "-" + version + " successfully!"); }
From source file:net.polydawn.mdm.commands.MdmAddCommand.java
License:Open Source License
void doGitStage(File path) { try {/*from www. j a v a 2s.com*/ new Git(repo).add().addFilepattern(path.getPath()).addFilepattern(Constants.DOT_GIT_MODULES).call(); } catch (NoFilepatternException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } }
From source file:net.polydawn.mdm.commands.MdmAddCommand.java
License:Open Source License
void doGitCommit(File path) throws MdmRepositoryStateException { String currentAction = "commit a link to the new dependency repo into the project repo"; try {/*from w ww .j a v a2 s .c om*/ new Git(repo).commit().setOnly(path.getPath()).setOnly(Constants.DOT_GIT_MODULES) .setMessage("adding dependency on " + name + " at " + version + ".").call(); } catch (NoHeadException e) { throw new MdmRepositoryStateException(currentAction, repo.getWorkTree().toString(), e); } catch (NoMessageException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (UnmergedPathsException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (ConcurrentRefUpdateException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (WrongRepositoryStateException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } }
From source file:net.polydawn.mdm.commands.MdmAlterCommand.java
License:Open Source License
public MdmExitMessage call() throws ConfigInvalidException, IOException, MdmException { try {/*from ww w .jav a 2s. c o m*/ assertInRepoRoot(); } catch (MdmExitMessage e) { return e; } // touch up args a tad. tab completion in the terminal tends to suggest *almost* what you want, but with a trailing slash because it's a directory, and git doesn't like that slash. so, we'll sand down that sharp corner a bit. String name = args.getString("name"); if (name.endsWith("/")) name = name.substring(0, name.length() - 1); // load current module state StoredConfig gitmodulesCfg = new FileBasedConfig(new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES), repo.getFS()); try { gitmodulesCfg.load(); } catch (ConfigInvalidException e) { throw new MdmExitInvalidConfig(Constants.DOT_GIT_MODULES); } MdmModuleDependency module; try { module = MdmModuleDependency.load(repo, name, gitmodulesCfg); } catch (MdmModuleTypeException e) { return new MdmExitMessage(":(", "there is no mdm dependency by that name."); } // give a look at the remote path and see what versions are physically available. List<String> versions; try { //XXX: here the triplicate-and-then-some configuration is a tanglefuck again. do we use the origin, or the url in the submodule config, or the url that's initialized in the parent .git/config, or the url in the .gitmodules file, or some complicated fallback pattern that covers all of them, or initialize the ones that aren't yet, or...?? Original mdm took the value from .gitmodules, which is the least likely to be uninitialized, but also not the most correct. if (module.getRepo() == null) versions = Plumbing.getVersionManifest(repo, module.getUrlHistoric()); else versions = Plumbing.getVersionManifest(module.getRepo(), "origin"); } catch (InvalidRemoteException e) { return new MdmExitMessage(":(", "the submodule remote origin url isn't initialized. maybe run `mdm update` first so there's something in place before we alter?"); } catch (TransportException e) { return new MdmExitMessage(":'(", "transport failed! check that the submodule remote origin url is correct and reachable and try again?\n (error message: " + e.getMessage() + ")"); } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } if (versions.size() == 0) return new MdmExitMessage(":(", "no releases could be found at the submodule remote origin url -- it doesn't look like releases that mdm understands are there.\ncheck the origin url in the submodule's config. if this url worked in the past, maybe the project maintainers moved their releases repo?"); // if a specific version name was given, we'll just go straight at it; otherwise we present options interactively from the manifest of versions the remote reported. String version; if (args.getString("version") != null) { version = args.getString("version"); if (!versions.contains(version)) return new MdmExitMessage(":(", "no version labelled " + version + " available from the provided remote url."); } else { version = Loco.promptForVersion(os, versions); } // if you specify the version you already had, okay, we'll just put our tools down. if (module.getVersionName().equals(version)) return new MdmExitMessage(":I", "that version is already specified! no changes made."); // do the submodule/dependency dancing gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, module.getHandle(), MdmConfigConstants.Module.DEPENDENCY_VERSION.toString(), version); module = MdmModuleDependency.load(repo, module.getPath(), gitmodulesCfg); // reload the MdmModule completely because it's not yet implmented intelligently enough to be able to refresh a bunch of its cached state Plumbing.fetch(repo, module); gitmodulesCfg.save(); // don't do this save until after the fetch: if the fetch blows up, it's better that we don't have this mutated, because that leaves you with slightly stranger output from your next `mdm status` query. // commit the changes try { new Git(repo).add().addFilepattern(module.getPath()).addFilepattern(Constants.DOT_GIT_MODULES).call(); } catch (NoFilepatternException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } try { new Git(repo).commit().setOnly(module.getPath()).setOnly(Constants.DOT_GIT_MODULES) .setMessage("shifting dependency on " + name + " to version " + version + ".").call(); } catch (NoHeadException e) { throw new MdmException("your repository is in an invalid state!", e); } catch (NoMessageException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (UnmergedPathsException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (ConcurrentRefUpdateException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (WrongRepositoryStateException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } return new MdmExitMessage(":D", "altered dependency on " + name + " to version " + version + " successfully!"); }
From source file:net.polydawn.mdm.commands.MdmReleaseInitCommand.java
License:Open Source License
public MdmExitMessage call() throws IOException, MdmException { // check for clean working area. try {//from w w w . jav a2 s .c o m assertReleaseRepoAreaClean(); } catch (MdmExitMessage e) { return e; } // okay! make the new releases-repo. put a first commit it in to avoid awkwardness. Repository releaserepo = makeReleaseRepo(); makeReleaseRepoFoundingCommit(releaserepo); makeReleaseRepoInitBranch(releaserepo); // if we're not a submodule, we're now done here, otherwise, the rest of the work revolves around the parent repo. if (!asSubmodule) return new MdmExitMessage(":D", "releases repo initialized"); // add the new releases-repo as a submodule to the project repo. try { writeParentGitmoduleConfig(repo); } catch (ConfigInvalidException e) { throw new MdmExitInvalidConfig(Constants.DOT_GIT_MODULES); } writeReleaseRepoConfig(releaserepo); makeParentRepoLinkCommit(repo); return new MdmExitMessage(":D", "releases repo and submodule initialized"); }
From source file:net.polydawn.mdm.commands.MdmReleaseInitCommand.java
License:Open Source License
/** * Writes a new submodule block to the parentRepo's .gitmodules file declaring the * release repo, and initializes the local .git/config file to match. * * @param parentRepo/* www . j a v a 2s. c om*/ * @throws IOException * @throws ConfigInvalidException */ void writeParentGitmoduleConfig(Repository parentRepo) throws IOException, ConfigInvalidException { // write gitmodule config for the new submodule StoredConfig gitmodulesCfg = new FileBasedConfig( new File(parentRepo.getWorkTree(), Constants.DOT_GIT_MODULES), parentRepo.getFS()); gitmodulesCfg.load(); gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_PATH, path); gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL, remotePublicUrl); gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, MdmConfigConstants.Module.MODULE_TYPE.toString(), MdmModuleType.RELEASES.toString()); gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_UPDATE, "none"); gitmodulesCfg.save(); // initialize local parent repo config for the submodule MdmModuleRelease module = MdmModuleRelease.load(parentRepo, path, gitmodulesCfg); Plumbing.initLocalConfig(parentRepo, module); parentRepo.getConfig().save(); }
From source file:net.polydawn.mdm.commands.MdmReleaseInitCommand.java
License:Open Source License
/** * Commits the release repo path and the gitmodules file. * * @param repo/*from w w w .j a va 2 s . c om*/ * @throws MdmRepositoryStateException * @throws NoWorkTreeException */ void makeParentRepoLinkCommit(Repository repo) throws MdmRepositoryStateException { String currentAction = "commit a link to the new releases repo into the parent repo"; try { new Git(repo).add().addFilepattern(path).addFilepattern(Constants.DOT_GIT_MODULES).call(); } catch (NoFilepatternException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (GitAPIException e) { throw new MdmUnrecognizedError(e); } try { new Git(repo).commit().setOnly(path).setOnly(Constants.DOT_GIT_MODULES) .setMessage("initialize releases repo for " + name + ".").call(); } catch (NoHeadException e) { throw new MdmRepositoryStateException(currentAction, repo.getWorkTree().toString(), e); } catch (UnmergedPathsException e) { throw new MdmRepositoryStateException(currentAction, repo.getWorkTree().toString(), e); } catch (WrongRepositoryStateException e) { throw new MdmRepositoryStateException(currentAction, repo.getWorkTree().toString(), e); } catch (ConcurrentRefUpdateException e) { throw new MdmConcurrentException(e); } catch (NoMessageException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (GitAPIException e) { throw new MdmUnrecognizedError(e); } }