Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await index.addByPath(commitFile.filename);
}
await index.write();
const oid = await index.writeTree();
const head = await NodeGit.Reference.nameToId(repo, "HEAD");
const parent = await repo.getCommit(head);
const diff = await NodeGit.Diff.treeToIndex(repo, await parent.getTree(), null);
const patches = await diff.patches();
if (_.size(patches) === 0) {
return "";
}
// commit
const signature = NodeGit.Signature.now("KOTS Admin Console", "help@replicated.com");
const commitHash = await repo.createCommit("HEAD", signature, signature, commitMessage, oid, [parent]);
// push
const remote = await repo.getRemote("origin");
await remote.push([`refs/heads/${branch}:refs/heads/${branch}`], options);
return getGitProviderCommitUrl(gitOpsCreds.uri, commitHash, gitOpsCreds.provider);
} catch (err) {
throw new ReplicatedError(`Failed to create git commit ${err}`)
}
}
.then(function (repo) {
var signature = NodeGit.Signature.default(repo);
var initIndex;
repo.refreshIndex()
.then(function (index) {
initIndex = index;
return index.write();
})
.then(function (index) {
return initIndex.writeTree();
})
.then(function (oid) {
return repo.createCommit("HEAD", signature, signature, 'initial commit', oid, []);
})
.done(function () {
if (onInit) {
onInit({
}).then(function (parentCommit) {
var author = Git.Signature.default(repo)
var commiter = author
log.info('git', 'Commiting the changes to HEAD with author ' + author)
return repo.createCommit('HEAD', author, commiter, message, oid, [parentCommit])
}).then(function () {
return inquire.run({name: 'ok', message: 'Should the commit be pushed?', type: 'confirm'})
exports.mergeSubmodule = co.wrap(function *(metaIndex,
subName,
change,
message,
opener,
fetcher,
sig,
openOption) {
assert.instanceOf(metaIndex, NodeGit.Index);
assert.isString(subName);
assert.instanceOf(change, SubmoduleChange);
assert.isString(message);
assert.instanceOf(opener, Open.Opener);
assert.instanceOf(fetcher, SubmoduleFetcher);
assert.instanceOf(sig, NodeGit.Signature);
assert.isNumber(openOption);
let subRepo = yield opener.getSubrepo(subName, openOption);
const isHalfOpened = yield opener.isHalfOpened(subName);
const forceBare = openOption === SUB_OPEN_OPTION.FORCE_BARE;
const theirSha = change.newSha;
yield fetcher.fetchSha(subRepo, subName, theirSha);
if (null !== change.ourSha) {
yield fetcher.fetchSha(subRepo, subName, change.ourSha);
}
const theirCommit = yield subRepo.getCommit(theirSha);
const ourSha = change.ourSha;
const ourCommit = yield subRepo.getCommit(ourSha);
async commitAndPush(message, { name, email }) {
const author = git.Signature.now(name, email);
const pusher = git.Signature.now('tweek-editor', 'tweek-editor@tweek');
await this._repo.createCommitOnHead([], author, pusher, message);
await this._pushRepositoryChanges(message);
}
async commitAndPush(message, { name, email }) {
const author = Git.Signature.now(name, email);
const pusher = Git.Signature.now('tweek-backoffice', 'tweek-backoffice@tweek');
await this._repo.createCommitOnHead([], author, pusher, message);
await this._pushRepositoryChanges(message);
}
const createSignature = (
time?: number = parseInt(Date.now() / 1000, 10),
offset?: number = new Date().getTimezoneOffset()
): Signature =>
Git.Signature.create("API", "api@amazee.io", time, offset);
exports.defaultSignature = co.wrap(function*(repo) {
assert.instanceOf(repo, NodeGit.Repository);
const config = yield repo.config();
const email = yield exports.getConfigString(config, "user.email");
const name = yield exports.getConfigString(config, "user.name");
if (name && email) {
const now = new Date();
const tz = now.getTimezoneOffset();
return NodeGit.Signature.create(name, email, now.getTime() / 1000, tz);
}
throw new UserError("Git config vars user.email and user.name are unset");
});
const index = yield repo.index();
const treeOid = yield index.writeTree();
const indexTree = yield repo.getTree(treeOid);
const newTree = yield TreeUtil.writeTree(repo, indexTree, changes);
if (null !== head) {
parents.push(head);
const headTree = yield head.getTree();
if (newTree.id().equal(headTree.id())) {
return head.sha();
}
}
let sig = yield ConfigUtil.defaultSignature(repo);
if (incrementTimestamp && null !== head) {
sig = NodeGit.Signature.create(sig.name(),
sig.email(),
head.time() + 1,
head.timeOffset());
}
const id = yield NodeGit.Commit.create(repo,
null,
sig,
sig,
null,
message,
newTree,
parents.length,
parents);
return id.tostrS();
});
export default () => {
const time = parseInt(Date.now() / 1000, 10);
const offset = new Date().getTimezoneOffset();
return Git.Signature.create('API', 'api@amazee.io', time, offset);
};