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:net.polydawn.mdm.commands.MdmRemoveCommand.java
License:Open Source License
public MdmExitMessage call() throws IOException, MdmException { try {// ww w. j av a 2s. co 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.commands.MdmStatusCommand.java
License:Open Source License
public MdmExitMessage call() throws IOException { try {/* w w w. j a v a 2s . c o m*/ assertInRepo(); } catch (MdmExitMessage e) { return e; } MdmModuleSet moduleSet; try { moduleSet = new MdmModuleSet(repo); } catch (ConfigInvalidException e) { throw new MdmExitInvalidConfig(Constants.DOT_GIT_MODULES); } Map<String, MdmModuleDependency> modules = moduleSet.getDependencyModules(); if (modules.size() == 0) { os.println(" --- no managed dependencies --- "); return new MdmExitMessage(0); } Collection<String> row1 = new ArrayList<String>(modules.keySet()); row1.add("dependency:"); int width1 = Strings.chooseFieldWidth(row1); os.printf("%-" + width1 + "s \t %s\n", "dependency:", "version:"); os.printf("%-" + width1 + "s \t %s\n", "-----------", "--------"); for (MdmModuleDependency mod : modules.values()) { StatusTuple status = status(mod); os.printf(" %-" + width1 + "s \t %s\n", mod.getHandle(), status.version); for (String warning : status.warnings) os.printf(" %-" + width1 + "s \t %s\n", "", " !! " + warning); } return new MdmExitMessage(0); }
From source file:net.polydawn.mdm.commands.MdmUpdateCommand.java
License:Open Source License
public MdmExitMessage call() throws ConfigInvalidException, IOException { try {/*from ww w .ja v a 2 s .com*/ assertInRepo(); } catch (MdmExitMessage e) { return e; } MdmModuleSet moduleSet; try { moduleSet = new MdmModuleSet(repo); } catch (ConfigInvalidException e) { throw new MdmExitInvalidConfig(Constants.DOT_GIT_MODULES); } Map<String, MdmModuleDependency> modules = moduleSet.getDependencyModules(); // Go over every module and do what we can to it, keeping a list of who each kind of operation was performed on for summary output later. List<MdmModule> impacted = new ArrayList<MdmModule>(); List<MdmModule> unphased = new ArrayList<MdmModule>(); List<MdmModule> contorted = new ArrayList<MdmModule>(); int hashMismatchWarnings = 0; int i = 0; boolean fancy = System.console() != null; for (MdmModuleDependency module : modules.values()) { i++; try { os.print((fancy ? "\033[2K\r" : "") + "updating module " + i + " of " + modules.size() + ": " + module.getHandle() + " ..." + (fancy ? "" : "\n")); if (Plumbing.fetch(repo, module)) { impacted.add(module); if (!module.getRepo().resolve(Constants.HEAD).equals(module.getIndexId())) { // in putting the module to the version named in .gitmodules, we made it disagree with the parent index. // this probably indicates oddness. hashMismatchWarnings++; os.println((fancy ? "\033[2K\r" : "") + "notice: in updating " + module.getHandle() + " to version " + module.getVersionName() + ", mdm left the submodule with a different hash checked out than the parent repo expected."); } } else unphased.add(module); } catch (MdmException e) { os.println((fancy ? "\033[2K\r" : "") + "error: in updating " + module.getHandle() + " to version " + module.getVersionName() + ", " + e); contorted.add(module); } } os.print((fancy ? "\033[2K\r" : "")); // explain notices about hash mismatches, if any occured. if (hashMismatchWarnings > 0) { os.println(); os.println( "warnings about submodule checkouts not matching the hash expected by the parent repo may indicate a problem which you should investigate immediately to make sure your dependencies are repeatable to others."); os.println( "this issue may be because the repository you are fetching from has moved what commit the version branch points to (which is cause for concern), or it may be a local misconfiguration (did you resolve a merge conflict recently? audit your log; the version name in gitmodules config must move at the same time as the submodule hash)."); os.println(); } else if (contorted.size() > 0) { os.println(); } // That's all. Compose a status string. StringBuilder status = new StringBuilder(); status.append("mdm dependencies have been updated ("); status.append(impacted.size()).append(" changed, "); status.append(unphased.size()).append(" unaffected"); if (contorted.size() > 0) status.append(", ").append(contorted.size()).append(" contorted"); status.append(")"); if (impacted.size() > 0) status.append("\n changed: \t").append(join(toHandles(impacted), "\n\t\t")); if (contorted.size() > 0) status.append("\n contorted: \t").append(join(toHandles(contorted), "\n\t\t")); return new MdmExitMessage(contorted.size() > 0 ? ":(" : ":D", status.toString()); }
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();//from w w w .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:org.eclipse.egit.ui.submodule.SubmoduleSyncTest.java
License:Open Source License
@Test public void syncSubmodule() throws Exception { deleteAllProjects();//from ww w . j a v a2 s . c om 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)); }