List of usage examples for org.eclipse.jgit.lib ConfigConstants CONFIG_SUBMODULE_SECTION
String CONFIG_SUBMODULE_SECTION
To view the source code for org.eclipse.jgit.lib ConfigConstants CONFIG_SUBMODULE_SECTION.
Click Source Link
From source file:com.tactfactory.harmony.utils.GitUtils.java
License:Open Source License
/** * Add a submodule to .gitmodules file./*from w ww. j a va2s . 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
Config doSubmoduleConfig(Config gitmodulesCfg, File path) { // write gitmodule config for the new submodule String slashedPath = (File.separatorChar != '/') ? path.getPath().replace(File.separatorChar, '/') : path.getPath();//from ww w .jav a 2 s. c om gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, slashedPath, ConfigConstants.CONFIG_KEY_PATH, slashedPath); gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, slashedPath, ConfigConstants.CONFIG_KEY_URL, url); gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, slashedPath, MdmConfigConstants.Module.MODULE_TYPE.toString(), MdmModuleType.DEPENDENCY.toString()); gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, slashedPath, MdmConfigConstants.Module.DEPENDENCY_VERSION.toString(), version); gitmodulesCfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, slashedPath, ConfigConstants.CONFIG_KEY_UPDATE, "none"); // since almost all git commands by default will pull down waaaay too much data if they operate naively on our dependencies, we tell them to ignore all dependencies by default. And of course, commands like `git pull` just steamroll right ahead and ignore this anyway, so those require even more drastic counters. return gitmodulesCfg; }
From source file:net.polydawn.mdm.commands.MdmAlterCommand.java
License:Open Source License
public MdmExitMessage call() throws ConfigInvalidException, IOException, MdmException { try {//from w w w . j ava2 s .com 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
/** * 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/*from ww w .ja va 2s . co m*/ * @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.MdmRemoveCommand.java
License:Open Source License
public MdmExitMessage call() throws IOException, MdmException { try {//from w w w . j a v a2 s . 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 up config 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); } // if there's no module there, we haven't got much to do try { MdmModuleDependency.load(repo, name, gitmodulesCfg); } catch (MdmModuleTypeException _) { return new MdmExitMessage(":I", "there is no mdm dependency by that name."); } // stage the remove and blow away the repo dirs try { new Git(repo).rm().setCached(true).addFilepattern(name).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); } IOForge.delete(new File(repo.getWorkTree(), name)); IOForge.delete(new File(repo.getDirectory(), "modules/" + name)); // if this is one of the newer version of git (specifically, 1.7.8 or newer) that stores the submodule's data in the parent projects .git dir, clear that out forcefully as well. // blow away gitmodule config section gitmodulesCfg.unsetSection(ConfigConstants.CONFIG_SUBMODULE_SECTION, name); gitmodulesCfg.save(); // commit the changes try { new Git(repo).add().addFilepattern(name).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(name).setOnly(Constants.DOT_GIT_MODULES) .setMessage("removing dependency on " + name + ".").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); } // clear out local git config StoredConfig localConfig = repo.getConfig(); localConfig.unsetSection(ConfigConstants.CONFIG_SUBMODULE_SECTION, name); localConfig.save(); return new MdmExitMessage(":D", "removed dependency on " + name + "!"); }
From source file:net.polydawn.mdm.MdmModule.java
License:Open Source License
/** * @param repo/*from w w w . ja v a 2 s .c o m*/ * required. * * well, unless you're about to create one, in which case not even. * @param handle * required. * @param parent * null if repository stands alone, otherwise if we are a submodule * required. * @param gitmodulesCfg * ignored if parent null, otherwise required. * @param indexId * ignored if parent null, otherwise will be automatically loaded * if not provided. * * the commit hash known to the parent repo index for this * submodule (or null if it's not handy; we'll load it in that * case). * * @throws MdmModuleTypeException * if the {@code gitmodulesCfg} entries for {@code handle} don't * concur with the {@code type} expected. * @throws MdmRepositoryIOException * if disks reject our advances */ protected MdmModule(Repository repo, String handle, Repository parent, Config gitmodulesCfg, ObjectId indexId) throws MdmRepositoryIOException, MdmModuleTypeException { handle = (File.separatorChar != '/') ? handle.replace(File.separatorChar, '/') : handle; this.handle = handle; this.repo = repo; if (repo == null) { this.headId = null; this.dirtyFiles = false; } else { try { this.headId = repo.resolve(Constants.HEAD); } catch (IOException e) { throw new MdmRepositoryIOException(false, handle, e); } boolean dirtyFiles; try { dirtyFiles = !new Git(repo).status().call().isClean(); } catch (NoWorkTreeException e) { throw new RuntimeException("wat", e); } catch (GitAPIException e) { dirtyFiles = false; } this.dirtyFiles = dirtyFiles; } if (parent != null) { // sanity check the expected module type if we're a submodule (if we're not a submodule, we can't make any such check since there's no gitmodules file to refer to). MdmModuleType type = getType(); MdmModuleType type_configured = MdmModuleType .fromString(gitmodulesCfg.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, handle, MdmConfigConstants.Module.MODULE_TYPE.toString())); if (type == null) throw new MdmModuleTypeException("expected module of type " + type + " for repository " + handle + ", but gitmodules file has no known type for this module."); if (type != type_configured) throw new MdmModuleTypeException("expected module of type " + type + " for repository " + handle + ", but gitmodules file states this is a " + type_configured + " module."); // load real path from gitmodule config (probably same as handle, but theoretically allowed to be different) String path = gitmodulesCfg.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, handle, ConfigConstants.CONFIG_KEY_PATH); this.path = (File.separatorChar != '/') ? path.replace(File.separatorChar, '/') : path; // load remote urls this.urlHistoric = gitmodulesCfg.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, handle, ConfigConstants.CONFIG_KEY_URL); this.urlLocal = parent.getConfig().getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, handle, ConfigConstants.CONFIG_KEY_URL); // load indexId the parent expects the submodule to be at (if not already provided) if (indexId != null) this.indexId = indexId; else try { SubmoduleWalk generator = SubmoduleWalk.forIndex(parent).setFilter(PathFilter.create(path)); this.indexId = generator.next() ? generator.getObjectId() : null; } catch (IOException e) { throw new MdmRepositoryIOException(false, parent.getWorkTree().getPath(), e); } // review the submodule and summarize a status. SubmoduleStatusType statusType; if (path == null) // jgit report SubmoduleStatusType.MISSING if no path in .gitmodules file, but I don't even want to deal with that. throw new MdmModuleTypeException("no path for module " + handle + " listed in gitmodules file."); else if (urlLocal == null) // Report uninitialized if no URL in config file statusType = SubmoduleStatusType.UNINITIALIZED; else if (repo == null) // Report uninitialized if no submodule repository statusType = SubmoduleStatusType.UNINITIALIZED; else if (headId == null) // Report uninitialized if no HEAD commit in submodule repository statusType = SubmoduleStatusType.UNINITIALIZED; else if (!headId.equals(indexId)) // Report checked out if HEAD commit is different than index commit statusType = SubmoduleStatusType.REV_CHECKED_OUT; else // Report initialized if HEAD commit is the same as the index commit statusType = SubmoduleStatusType.INITIALIZED; this.status = new SubmoduleStatus(statusType, path, indexId, headId); } else { this.path = handle; this.indexId = null; this.urlHistoric = null; this.urlLocal = null; this.status = null; } }
From source file:net.polydawn.mdm.MdmModuleSet.java
License:Open Source License
public MdmModuleSet(Repository repo) throws IOException, ConfigInvalidException { gitmodulesCfg = new FileBasedConfig(new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES), repo.getFS()); gitmodulesCfg.load();// www .j a v a2 s.co m /* * To maximize similarity with how the `git submodule` command behaves, we treat the SubmoduleWalk as canonical and the content of the .gitmodules file as tertiary. * However, that may change. There's a lot about MdmModule that doesn't work without a .gitmodules entry anyway, so if it's faster to start from that list, we might as well. */ SubmoduleWalk mw = new SubmoduleWalk(repo); mw.setModulesConfig(gitmodulesCfg); SubmoduleWalk generator = SubmoduleWalk.forIndex(repo); while (generator.next()) { try { // get the handle. which we presume to be rather like the path, but git config always uses forward slashes. // (the MdmModule constructor will also enforce this, but here we have to walk config ourselves before we get that far.) String handle = (File.separatorChar != '/') ? generator.getPath().replace(File.separatorChar, '/') : generator.getPath(); // get submodule.[handle].mdm config value from gitmodules config file String type_configured_string = gitmodulesCfg.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, handle, MdmConfigConstants.Module.MODULE_TYPE.toString()); MdmModuleType type_configured = MdmModuleType.fromString(type_configured_string); // if the submodule.[handle].mdm config value was unrecognized or missing, ignore; it's not ours. if (type_configured == null) continue; // load whichever type of mdm module it is switch (type_configured) { case DEPENDENCY: MdmModuleDependency modDep = MdmModuleDependency.load(repo, generator, gitmodulesCfg); dependencyModules.put(modDep.getHandle(), modDep); allModules.put(modDep.getHandle(), modDep); break; case RELEASES: MdmModuleRelease modRel = MdmModuleRelease.load(repo, generator, gitmodulesCfg); releasesModules.put(modRel.getHandle(), modRel); allModules.put(modRel.getHandle(), modRel); break; } } catch (MdmModuleTypeException e) { throw new MajorBug(e); } catch (MdmRepositoryNonexistant e) { throw e; } catch (MdmRepositoryIOException e) { throw e; } } }
From source file:net.polydawn.mdm.Plumbing.java
License:Open Source License
/** * Similar to calling `git submodule init [module]`. Also updates the MdmModule cache of values. * @return true if repo.getConfig() has been modified and should be saved. */// ww w. j a v a2 s. c o m public static boolean initLocalConfig(Repository repo, MdmModule module) { // Ignore entry if URL is already present in config file if (module.getUrlLocal() != null) return false; // Copy 'url' and 'update' fields to local repo config module.urlLocal = module.getUrlHistoric(); repo.getConfig().setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, module.getHandle(), ConfigConstants.CONFIG_KEY_URL, module.getUrlLocal()); repo.getConfig().setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, module.getHandle(), ConfigConstants.CONFIG_KEY_UPDATE, "none"); return true; }
From source file:org.eclipse.egit.ui.submodule.SubmoduleSyncTest.java
License:Open Source License
@Test public void syncSubmodule() throws Exception { deleteAllProjects();//from ww w . jav a 2 s . c o m assertProjectExistence(PROJ1, false); clearView(); Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile); shareProjects(repositoryFile); assertProjectExistence(PROJ1, true); refreshAndWait(); assertHasRepo(repositoryFile); FileRepository repo = lookupRepository(repositoryFile); SubmoduleAddCommand command = new SubmoduleAddCommand(repo); String path = "sub"; command.setPath(path); String uri = new URIish(repo.getDirectory().toURI().toString()).toString(); command.setURI(uri); Repository subRepo = command.call(); assertNotNull(subRepo); String newUri = "git://server/repo.git"; File modulesFile = new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES); FileBasedConfig config = new FileBasedConfig(modulesFile, repo.getFS()); config.load(); config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL, newUri); config.save(); assertEquals(uri, repo.getConfig().getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL)); assertEquals(uri, subRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL)); refreshAndWait(); SWTBotTree tree = getOrOpenView().bot().tree(); tree.getAllItems()[0].expand().expandNode(UIText.RepositoriesViewLabelProvider_SubmodulesNodeText).select(); ContextMenuHelper.clickContextMenuSync(tree, myUtil.getPluginLocalizedValue(SYNC_SUBMODULE_CONTEXT_MENU_LABEL)); TestUtil.joinJobs(JobFamilies.SUBMODULE_SYNC); refreshAndWait(); assertEquals(newUri, repo.getConfig().getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL)); assertEquals(newUri, subRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL)); }