Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/project/gitconfig.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { constants as fs_constants } from "fs";6import { access, writeFile } from "fs/promises";7import { homedir } from "os";8import { join } from "path";9import { executeCode } from "@cocalc/backend/execute-code";1011const EXCLUDES_FN = join(homedir(), ".gitexcludes");1213const EXCLUDES = `\14# Global .gitignore file15# You can edit this file, CoCalc will not change it.16# configured via ~/.gitconfig: core/excludesfile1718### CoCalc Platform ###19/.snapshots/20.*.sage-chat21.*.sage-history22.*.sage-jupyter23.*.sage-jupyter224.*.syncdb25.*.syncdoc26.*.syncdoc[34]2728### Linux hidden files ###29/.*30*~3132### Python ###33__pycache__/34*.py[cod]3536# SageMath parsed files37*.sage.py3839# mypy typechecker40.mypy_cache/4142### JupyterNotebooks ###43.ipynb_checkpoints/4445### LaTeX ###46# Core latex/pdflatex auxiliary files:47*.aux48*.lof49*.log50*.lot51*.fls52*.out53*.toc54*.fmt55*.fot56*.cb57*.cb258.*.lb5960# Bibliography auxiliary files (bibtex/biblatex/biber):61*.bbl62*.bcf63*.blg64*-blx.aux65*-blx.bib66*.run.xml6768# Build tool auxiliary files:69*.fdb_latexmk70*.synctex71*.synctex(busy)72*.synctex.gz73*.synctex.gz(busy)74*.pdfsync7576# knitr77*-concordance.tex7879# sagetex80*.sagetex.sage81*.sagetex.py82*.sagetex.scmd8384# pythontex85*.pytxcode86pythontex-files-*/87`;8889// initialize files in a project to help working with git90export async function init_gitconfig(winston: {91debug: Function;92}): Promise<void> {93const conf = await executeCode({94command: "git",95args: ["config", "--global", "--get", "core.excludesfile"],96bash: false,97err_on_exit: false,98});99// exit_code == 1 if key isn't set. only then we check if there is no file and do the setup100if (conf.exit_code != 0) {101winston.debug("git: core.excludesfile key not set");102try {103// throws if files doesn't exist104await access(EXCLUDES_FN, fs_constants.F_OK);105winston.debug(`git: excludes file '${EXCLUDES_FN}' exists -> abort`);106return;107} catch {}108winston.debug(109`git: writing '${EXCLUDES_FN}' file and setting global git config`110);111await writeFile(EXCLUDES_FN, EXCLUDES, "utf8");112await executeCode({113command: "git",114args: ["config", "--global", "--add", "core.excludesfile", EXCLUDES_FN],115bash: false,116});117}118}119120121