Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as Git from 'nodegit';
Git.Repository.discover("startPath", 1, "ceilingDirs").then((string) => {
// Use string
});
Git.Repository.init("path", 0).then((repository) => {
// Use repository
});
const repo = new Git.Repository();
const id = new Git.Oid();
const ref = new Git.Reference();
const tree = new Git.Tree();
tree.walk().start();
tree.getEntry("/").then(entry => {
// Use entry
});
// AnnotatedCommit Tests
Git.AnnotatedCommit.fromFetchhead(repo, "branch_name", "remote_url", id).then((annotatedCommit) => {
// Use annotatedCommit
});
Git.AnnotatedCommit.fromRef(repo, ref).then((annotatedCommit) => {
log: "A repository was not found. Try creating one, pasting the clone URL in the first field and click on 'Update'",
type: 'error',
time: help.getCurrentTime()
}
socket.emit('updateLog', item);
callback({type:'error', log:"Something went wrong, try to click on 'Update'."});
callback = null;
}
return;
}else{
throw err;
}
})
//Try to open the repository on ./git/
Git.Repository.open('./git/')
.then(function(repo) {
repository = repo;
return repository.fetchAll({
callbacks: {
/* istanbul ignore next */
credentials: function(url, userName) {
return Git.Cred.sshKeyFromAgent(userName);
},
certificateCheck: function() {
return 1;
}
}
});
})
// Now that we're finished fetching, go ahead and merge our local branch
const cloneOptions = {
fetchOpts: {
callbacks: {
certificateCheck: () => { return 0; },
credentials: async (url, username) => {
const creds = await NodeGit.Cred.sshKeyMemoryNew(username, gitOpsCreds.pubKey, decryptedPrivateKey, "")
return creds;
}
}
},
};
try {
await NodeGit.Clone(gitOpsCreds.cloneUri, localPath, cloneOptions);
NodeGit.Repository.openBare(localPath);
// TODO check if we have write access!
await stores.kotsAppStore.setGitOpsError(appId, clusterId, "");
// Send current and pending versions to git
// We need a persistent, durable queue for this to handle the api container
// being rescheduled during this long-running operation
const clusterIDs = await stores.kotsAppStore.listClusterIDsForApp(appId);
if (clusterIDs.length === 0) {
throw new Error("no clusters to transition for application");
}
// NOTE (ethan): this is asyncronous but i didn't write the code
sendInitialGitCommitsForAppDownstream(stores, appId, clusterIDs[0]);
return true;
} catch (err) {
remote = 'origin',
preview = false,
ignore = 'origin/master',
age = '1m',
password
}) {
if (!path) {
throw new Error('Path is required');
}
try {
const cutoffMoment = age ? getCutoffMoment(age) : null;
const ignoreList = await getConfiguredIgnoresIfExist(path);
ignoreList.push(...ignore);
const repo = await NodeGit.Repository.open(path);
const authTrials = {
agent: false,
userpassPlaintext: false
};
await repo.fetch(remote, {
callbacks: {
certificateCheck: function() { return 1; },
credentials: function(url, username) {
// Do not try ssh-agent if password is specified
if (password) {
if (!authTrials.userpassPlaintext) {
authTrials.userpassPlaintext = true;
return NodeGit.Cred.userpassPlaintextNew(username, password);
}
} else if (!authTrials.agent) {
const sync = (async function*() {
try {
console.log(messages.get(21));
const repository = await git.Repository.open(GIT_ROOT);
const author = git.Signature.default(repository);
while (true) {
yield;
const statuses = await repository.getStatus();
if (statuses.length) {
const parent = await repository.getHeadCommit();
const index = await repository.refreshIndex();
const currentTime = getCurrentTime();
const commitMessage = `${COMMIT_PHRASE_START}: ${currentTime}`;
const logCommitMessage = `${chalk.greenBright(
COMMIT_PHRASE_START,
)}: ${chalk.blueBright(currentTime)}`;
async function runMigrations(fromFolder: string, toFolder: string) {
toFolder = argv.to as string || '.';
if (!fromFolder) {
throw new Error('Must specify --from option when migrating.');
}
fromFolder = resolvePath(fromFolder);
toFolder = resolvePath(toFolder);
if (fromFolder === toFolder) {
logger.info(null, '[migrate] Migration source and destination identical, skipping.');
return;
}
await bootstrapDatabase();
logger.info(null, '[migrate] Migrating from %s to %s...', fromFolder, toFolder);
const fromRepo = await Git.Repository.open(fromFolder);
const toRepo = await Git.Repository.open(toFolder);
const fromCommit = await fromRepo.getHeadCommit();
try {
await toRepo.getCommit(fromCommit.sha());
} catch (err) {
logger.warn(null, '[migrate] Cannot find commit %s in repository %s. Assuming force-push, aborting migrations.', fromCommit.sha(), toFolder);
return;
}
let foundFromCommit = false;
const toCommit = await toRepo.getHeadCommit();
const commits = await new Promise((resolve, reject) => {
const commitsSince: Commit[] = [];
const emitter = toCommit.history()
.on('end', () => resolve(commitsSince))
.on('error', reject)
.on('commit', (commit: Commit) => {
toFolder = argv.to as string || '.';
if (!fromFolder) {
throw new Error('Must specify --from option when migrating.');
}
fromFolder = resolvePath(fromFolder);
toFolder = resolvePath(toFolder);
if (fromFolder === toFolder) {
logger.info(null, '[migrate] Migration source and destination identical, skipping.');
return;
}
await bootstrapDatabase();
logger.info(null, '[migrate] Migrating from %s to %s...', fromFolder, toFolder);
const fromRepo = await Git.Repository.open(fromFolder);
const toRepo = await Git.Repository.open(toFolder);
const fromCommit = await fromRepo.getHeadCommit();
try {
await toRepo.getCommit(fromCommit.sha());
} catch (err) {
logger.warn(null, '[migrate] Cannot find commit %s in repository %s. Assuming force-push, aborting migrations.', fromCommit.sha(), toFolder);
return;
}
let foundFromCommit = false;
const toCommit = await toRepo.getHeadCommit();
const commits = await new Promise((resolve, reject) => {
const commitsSince: Commit[] = [];
const emitter = toCommit.history()
.on('end', () => resolve(commitsSince))
.on('error', reject)
.on('commit', (commit: Commit) => {
foundFromCommit = foundFromCommit || commit.sha() === fromCommit.sha();
openRepository () {
if (this._openExactPath) {
return Git.Repository.open(this.openedPath)
} else {
return Git.Repository.openExt(this.openedPath, 0, '')
}
}
async setup () {
const repoFolder = path.join(this.build.dir, 'repository')
let repo = null
try {
const stat = await fs.statAsync(repoFolder)
if (stat.isDirectory()) {
repo = await git.Repository.open(repoFolder)
} else {
const e = new Error()
e.code = 'ENOENT'
throw e
}
} catch (e) {
if (e.code === 'ENOENT') {
await fsHelper.mkdirp(repoFolder)
repo = await git.Clone(this.build.repo, repoFolder)
/**
* Clones all of the Git submodules for a given repo path
*
* @async
* @param {String} clonePath - Path of the repository
* @return {void}
export default async function pullRepository(
repoPath: string,
localPath: string,
): Promise {
try {
const callbacks = composeCallbacks(repoPath)
const repo = await NodeGit.Repository.open(localPath)
await repo.fetchAll({ callbacks })
await repo.mergeBranches('master', 'origin/master')
return repo
} catch (e) {
error('Error adding repository')
echo(chalk.red(e))
}
}