Skip to content

Commit b3d36f4

Browse files
Simplfy git commands
Thank you @stnguyen90 for this idea
1 parent 0810b84 commit b3d36f4

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

templates/cli/lib/commands/init.js.twig

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ const initFunction = async () => {
8181

8282
fs.mkdirSync(functionDir, "777");
8383

84-
const gitInitCommands =
85-
`git init && ` +
86-
`git remote add -f origin https://github.com/{{ sdk.gitUserName }}/functions-starter && ` +
87-
`git config core.sparseCheckout true`;
84+
const gitInitCommands = "git clone --depth 1 --sparse https://github.com/{{ sdk.gitUserName }}/functions-starter ."; // depth prevents fetching older commits reducing the amount fetched
8885

89-
const gitPullCommands = `git pull origin main`;
86+
const gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`;
9087

9188
// Force use CMD as powershell does not support &&
9289
if (process.platform == 'win32') {
@@ -95,11 +92,9 @@ const initFunction = async () => {
9592
}
9693

9794
// Execute the child process but do not print any std output
98-
childProcess.execSync(gitInitCommands, { stdio: 'pipe' });
95+
childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
9996

100-
fs.writeFileSync(path.join(functionDir, ".git/info/sparse-checkout"), `${answers.runtime.id}`);
101-
102-
childProcess.execSync(gitPullCommands, { stdio: 'pipe' });
97+
childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
10398

10499
fs.rmSync(path.join(functionDir, ".git"), { recursive: true });
105100
const copyRecursiveSync = (src, dest) => {
@@ -120,7 +115,7 @@ const initFunction = async () => {
120115
};
121116
copyRecursiveSync(path.join(functionDir, answers.runtime.id), functionDir);
122117

123-
fs.rmSync(`./${answers.name}/${answers.runtime.id}`, { recursive: true, force: true });
118+
fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });
124119

125120
const readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md');
126121
const readmeFile = fs.readFileSync(readmePath).toString();

0 commit comments

Comments
 (0)