R
Railway13mo ago
bephrem

Not In a git Directory

Hi, I have a NodeJS server I'm trying to deploy → it runs a build script that pulls code from Github (for a git submodule w/ files the main project reads from). I'm getting the error not in a git directory when I try to run git commands. Here is my script buildCms.js:
import config from '../src/config';
import { exec } from 'child_process';
import fs from 'fs';
import { logger } from '../src/modules/logging';
import { promisify } from 'util';

const execAsync = promisify(exec);

async function cleanCms() {
const cmsPath = './cms';

if (fs.existsSync(cmsPath)) {
try {
await fs.promises.rm(cmsPath, { recursive: true, force: true });
logger.info('cms cleaned successfully.');
} catch (err) {
logger.error('error cleaning cms', err);
}
}
}

async function cloneCms() {
const orgName = '__redacted';
const repoName = '__redacted';

const githubAccessToken = config.github.accessToken;
const cloneUrl = `https://${githubAccessToken}@github.com/${orgName}/${repoName}.git`;

try {
await execAsync(`git config submodule.${repoName}.url "${cloneUrl}"`);
await execAsync('git submodule update --init --recursive');
logger.info('cms cloned successfully.');
} catch (err) {
logger.error('failed to clone cms.', err);
}
}

async function main() {
await cleanCms();
await cloneCms();
}

main();
import config from '../src/config';
import { exec } from 'child_process';
import fs from 'fs';
import { logger } from '../src/modules/logging';
import { promisify } from 'util';

const execAsync = promisify(exec);

async function cleanCms() {
const cmsPath = './cms';

if (fs.existsSync(cmsPath)) {
try {
await fs.promises.rm(cmsPath, { recursive: true, force: true });
logger.info('cms cleaned successfully.');
} catch (err) {
logger.error('error cleaning cms', err);
}
}
}

async function cloneCms() {
const orgName = '__redacted';
const repoName = '__redacted';

const githubAccessToken = config.github.accessToken;
const cloneUrl = `https://${githubAccessToken}@github.com/${orgName}/${repoName}.git`;

try {
await execAsync(`git config submodule.${repoName}.url "${cloneUrl}"`);
await execAsync('git submodule update --init --recursive');
logger.info('cms cloned successfully.');
} catch (err) {
logger.error('failed to clone cms.', err);
}
}

async function main() {
await cleanCms();
await cloneCms();
}

main();
No description
Solution:
adding a await execAsync('git init'); as first command
Jump to solution
7 Replies
Percy
Percy13mo ago
Project ID: dcbbcdb7-cd29-4c80-9a47-6a3f66851471
Brody
Brody13mo ago
as far as I know, the .git folder is not included in the repo
bephrem
bephremOP13mo ago
maybe I need to run git init pretty sure if I just ran a normal git clone everything works (which makes sense considering that doesn't assume an initialized git repository) will try this - I originally thought that the git binary just wasn't there
Brody
Brody13mo ago
git clone will pull from a repo and make the .git folder and git init will initialize a .git folder
bephrem
bephremOP13mo ago
right yes git init worked - command now runs
Solution
bephrem
bephrem13mo ago
adding a await execAsync('git init'); as first command
bephrem
bephremOP13mo ago
updated (had to run git submodule add for the submodule to pull, odd because .gitmodules should be in the file tree, but I don't think git init pulls that data into the fresh .git folder's data)
async function cloneCms() {
const orgName = '__redacted';
const repoName = 'cms';
const submodulePath = repoName;

const githubAccessToken = config.github.accessToken;
const cloneUrl = `https://${githubAccessToken}@github.com/${orgName}/${repoName}.git`;

try {
if (config.isProduction) {
await execAsync('git init');
await execAsync(`git submodule add ${cloneUrl} ${submodulePath}`);
}

await execAsync('git submodule update --init --recursive');

logger.info('cms cloned successfully.');
} catch (err) {
logger.error('failed to clone cms.', err);
}
}
async function cloneCms() {
const orgName = '__redacted';
const repoName = 'cms';
const submodulePath = repoName;

const githubAccessToken = config.github.accessToken;
const cloneUrl = `https://${githubAccessToken}@github.com/${orgName}/${repoName}.git`;

try {
if (config.isProduction) {
await execAsync('git init');
await execAsync(`git submodule add ${cloneUrl} ${submodulePath}`);
}

await execAsync('git submodule update --init --recursive');

logger.info('cms cloned successfully.');
} catch (err) {
logger.error('failed to clone cms.', err);
}
}
Want results from more Discord servers?
Add your server