@cocalc/project
Version:
CoCalc: project daemon
120 lines (108 loc) • 2.77 kB
JavaScript
"use strict";
/*
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.init_gitconfig = void 0;
const util_1 = require("util");
const fs_1 = require("fs");
const writeFile = (0, util_1.promisify)(fs_1.writeFile);
const access = (0, util_1.promisify)(fs_1.access);
const os_1 = require("os");
const path_1 = require("path");
const { execute_code } = require("@cocalc/backend/misc_node");
const { callback2: cb2 } = require("@cocalc/util/async-utils");
const EXCLUDES_FN = (0, path_1.join)((0, os_1.homedir)(), ".gitexcludes");
const EXCLUDES = `\
# Global .gitignore file
# You can edit this file, CoCalc will not change it.
# configured via ~/.gitconfig: core/excludesfile
### CoCalc Platform ###
/.snapshots/
.*.sage-chat
.*.sage-history
.*.sage-jupyter
.*.sage-jupyter2
.*.syncdb
.*.syncdoc
.*.syncdoc[34]
### Linux hidden files ###
/.*
*~
### Python ###
__pycache__/
*.py[cod]
# SageMath parsed files
*.sage.py
# mypy typechecker
.mypy_cache/
### JupyterNotebooks ###
.ipynb_checkpoints/
### LaTeX ###
# Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb
# Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
# Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
# knitr
*-concordance.tex
# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd
# pythontex
*.pytxcode
pythontex-files-*/
`;
// initialize files in a project to help working with git
async function init_gitconfig(winston) {
const conf = await cb2(execute_code, {
command: "git",
args: ["config", "--global", "--get", "core.excludesfile"],
bash: false,
err_on_exit: false,
});
// exit_code == 1 if key isn't set. only then we check if there is no file and do the setup
if (conf.exit_code != 0) {
winston.debug("git: core.excludesfile key not set");
try {
// throws if files doesn't exist
await access(EXCLUDES_FN, fs_1.constants.F_OK);
winston.debug(`git: excludes file '${EXCLUDES_FN}' exists -> abort`);
return;
}
catch { }
winston.debug(`git: writing '${EXCLUDES_FN}' file and setting global git config`);
await writeFile(EXCLUDES_FN, EXCLUDES, "utf8");
await cb2(execute_code, {
command: "git",
args: ["config", "--global", "--add", "core.excludesfile", EXCLUDES_FN],
bash: false,
});
}
}
exports.init_gitconfig = init_gitconfig;
//# sourceMappingURL=gitconfig.js.map