CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/gitconfig.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { constants as fs_constants } from "fs";
7
import { access, writeFile } from "fs/promises";
8
import { homedir } from "os";
9
import { join } from "path";
10
import { executeCode } from "@cocalc/backend/execute-code";
11
12
const EXCLUDES_FN = join(homedir(), ".gitexcludes");
13
14
const EXCLUDES = `\
15
# Global .gitignore file
16
# You can edit this file, CoCalc will not change it.
17
# configured via ~/.gitconfig: core/excludesfile
18
19
### CoCalc Platform ###
20
/.snapshots/
21
.*.sage-chat
22
.*.sage-history
23
.*.sage-jupyter
24
.*.sage-jupyter2
25
.*.syncdb
26
.*.syncdoc
27
.*.syncdoc[34]
28
29
### Linux hidden files ###
30
/.*
31
*~
32
33
### Python ###
34
__pycache__/
35
*.py[cod]
36
37
# SageMath parsed files
38
*.sage.py
39
40
# mypy typechecker
41
.mypy_cache/
42
43
### JupyterNotebooks ###
44
.ipynb_checkpoints/
45
46
### LaTeX ###
47
# Core latex/pdflatex auxiliary files:
48
*.aux
49
*.lof
50
*.log
51
*.lot
52
*.fls
53
*.out
54
*.toc
55
*.fmt
56
*.fot
57
*.cb
58
*.cb2
59
.*.lb
60
61
# Bibliography auxiliary files (bibtex/biblatex/biber):
62
*.bbl
63
*.bcf
64
*.blg
65
*-blx.aux
66
*-blx.bib
67
*.run.xml
68
69
# Build tool auxiliary files:
70
*.fdb_latexmk
71
*.synctex
72
*.synctex(busy)
73
*.synctex.gz
74
*.synctex.gz(busy)
75
*.pdfsync
76
77
# knitr
78
*-concordance.tex
79
80
# sagetex
81
*.sagetex.sage
82
*.sagetex.py
83
*.sagetex.scmd
84
85
# pythontex
86
*.pytxcode
87
pythontex-files-*/
88
`;
89
90
// initialize files in a project to help working with git
91
export async function init_gitconfig(winston: {
92
debug: Function;
93
}): Promise<void> {
94
const conf = await executeCode({
95
command: "git",
96
args: ["config", "--global", "--get", "core.excludesfile"],
97
bash: false,
98
err_on_exit: false,
99
});
100
// exit_code == 1 if key isn't set. only then we check if there is no file and do the setup
101
if (conf.exit_code != 0) {
102
winston.debug("git: core.excludesfile key not set");
103
try {
104
// throws if files doesn't exist
105
await access(EXCLUDES_FN, fs_constants.F_OK);
106
winston.debug(`git: excludes file '${EXCLUDES_FN}' exists -> abort`);
107
return;
108
} catch {}
109
winston.debug(
110
`git: writing '${EXCLUDES_FN}' file and setting global git config`
111
);
112
await writeFile(EXCLUDES_FN, EXCLUDES, "utf8");
113
await executeCode({
114
command: "git",
115
args: ["config", "--global", "--add", "core.excludesfile", EXCLUDES_FN],
116
bash: false,
117
});
118
}
119
}
120
121