Newer
Older
dub_jkp / source / dub / git.d
  1. // functionality to supply packages from git submodules
  2. module dub.git;
  3.  
  4. import dub.dependency;
  5. import dub.internal.vibecompat.core.file;
  6. import dub.package_;
  7. import dub.packagemanager;
  8.  
  9. import std.algorithm;
  10. import std.ascii : newline;
  11. import std.exception : enforce;
  12. import std.range;
  13. import std.string;
  14.  
  15. /** Adds the git submodules checked out in the root path as direct packages.
  16. Package version is derived from the submodule's tag by `getOrLoadPackage`.
  17.  
  18. Params:
  19. packageManager = Package manager to track the added packages.
  20. rootPath = the root path of the git repository to check for submodules.
  21. */
  22. public void addGitSubmodules(PackageManager packageManager, NativePath rootPath) {
  23. import std.process : execute;
  24.  
  25. const submoduleInfo = execute(["git", "--git-dir=" ~ (rootPath ~ ".git").toNativeString, "submodule", "status"]);
  26.  
  27. enforce(submoduleInfo.status == 0,
  28. format("git submodule status exited with error code %s: %s", submoduleInfo.status, submoduleInfo.output));
  29.  
  30. foreach (line; submoduleInfo.output.lines) {
  31. const parts = line.split(" ").map!strip.filter!(a => !a.empty).array;
  32. const subPath = rootPath ~ parts[1];
  33. const packageFile = Package.findPackageFile(subPath);
  34.  
  35. if (packageFile != NativePath.init) {
  36. const scmPath = rootPath ~ NativePath(".git/modules/" ~ parts[1]);
  37. packageManager.getOrLoadPackage(subPath, packageFile, false, scmPath);
  38. }
  39. }
  40. }
  41.  
  42. private alias lines = text => text.split(newline).map!strip.filter!(a => !a.empty);