Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

git.js 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.stageFile = exports.getUnstagedChangedFiles = exports.getChangedFiles = exports.getSinceRevision = exports.detect = exports.name = void 0;
  6. var _findUp = _interopRequireDefault(require("find-up"));
  7. var _execa = _interopRequireDefault(require("execa"));
  8. var _path = require("path");
  9. var fs = _interopRequireWildcard(require("fs"));
  10. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  11. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. const name = 'git';
  14. exports.name = name;
  15. const detect = directory => {
  16. if (fs.existsSync((0, _path.join)(directory, '.git'))) {
  17. return directory;
  18. }
  19. const gitDirectory = _findUp.default.sync('.git', {
  20. cwd: directory,
  21. type: 'directory'
  22. });
  23. if (gitDirectory) {
  24. return (0, _path.dirname)(gitDirectory);
  25. }
  26. };
  27. exports.detect = detect;
  28. const runGit = (directory, args) => _execa.default.sync('git', args, {
  29. cwd: directory
  30. });
  31. const getLines = execaResult => execaResult.stdout.split('\n');
  32. const getSinceRevision = (directory, {
  33. staged,
  34. branch
  35. }) => {
  36. try {
  37. const revision = staged ? 'HEAD' : runGit(directory, ['merge-base', 'HEAD', branch || 'master']).stdout.trim();
  38. return runGit(directory, ['rev-parse', '--short', revision]).stdout.trim();
  39. } catch (error) {
  40. if (/HEAD/.test(error.message) || staged && /Needed a single revision/.test(error.message)) {
  41. return null;
  42. }
  43. throw error;
  44. }
  45. };
  46. exports.getSinceRevision = getSinceRevision;
  47. const getChangedFiles = (directory, revision, staged) => {
  48. return [...getLines(runGit(directory, ['diff', '--name-only', staged ? '--cached' : null, '--diff-filter=ACMRTUB', revision].filter(Boolean))), ...(staged ? [] : getLines(runGit(directory, ['ls-files', '--others', '--exclude-standard'])))].filter(Boolean);
  49. };
  50. exports.getChangedFiles = getChangedFiles;
  51. const getUnstagedChangedFiles = directory => {
  52. return getChangedFiles(directory, null, false);
  53. };
  54. exports.getUnstagedChangedFiles = getUnstagedChangedFiles;
  55. const stageFile = (directory, file) => {
  56. runGit(directory, ['add', file]);
  57. };
  58. exports.stageFile = stageFile;