Skip to content

Commit

Permalink
Update import statements for nodegit (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
bateau authored Jul 15, 2022
1 parent 5dd973d commit 835e7af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/utils/diffing/getFenceAndImportDiffsFromGit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Git from 'nodegit';
import { Diff, Repository } from 'nodegit';
import { loadConfigFromString } from '../loadConfig';
import Config from '../../types/config/Config';
import normalizePath from '../normalizePath';
Expand Down Expand Up @@ -47,15 +47,15 @@ export type FenceAndImportDiffs = {
export async function getFenceAndImportDiffsFromGit(
compareOidOrRefName: string
): Promise<FenceAndImportDiffs | null> {
const repo = await Git.Repository.open(process.cwd());
const repo = await Repository.open(process.cwd());
const [index, headCommitTree, compareTree] = await Promise.all([
repo.index(),
repo.getHeadCommit().then(headCommit => headCommit?.getTree?.()),
resolveHashOrRefToCommit(repo, compareOidOrRefName).then(commit => commit.getTree()),
]);

let repoDiff: Git.Diff;
const indexToHead = await Git.Diff.treeToIndex(repo, headCommitTree, null);
let repoDiff: Diff;
const indexToHead = await Diff.treeToIndex(repo, headCommitTree, null);
const indexIsEmpty = indexToHead.numDeltas() === 0;

// Permit all extensions in the extension set. If we are
Expand All @@ -72,12 +72,12 @@ export async function getFenceAndImportDiffsFromGit(
});

if (!indexIsEmpty) {
repoDiff = await Git.Diff.treeToIndex(repo, compareTree, index, {
repoDiff = await Diff.treeToIndex(repo, compareTree, index, {
contextLines: 0,
pathspec: mostPermissiveExtensionSet.map(dotExt => '*' + dotExt),
});
} else {
repoDiff = await Git.Diff.treeToTree(repo, compareTree, headCommitTree, {
repoDiff = await Diff.treeToTree(repo, compareTree, headCommitTree, {
contextLines: 0,
pathspec: mostPermissiveExtensionSet.map(dotExt => '*' + dotExt),
});
Expand Down
4 changes: 2 additions & 2 deletions src/utils/diffing/getFenceAndSourcePatches.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as Git from 'nodegit';
import { Diff } from 'nodegit';

/**
* Given a nodegit Diff object, partitions it by path
* into diffs between fences or script files. Ignores any paths
* that are neither fences nor script files
*/
export async function getFenceAndSourcePatches(diffSinceHash: Git.Diff, extensions: string[]) {
export async function getFenceAndSourcePatches(diffSinceHash: Diff, extensions: string[]) {
const patches = await diffSinceHash.patches();
const fencePatches = [];
const sourcePatches = [];
Expand Down
14 changes: 7 additions & 7 deletions src/utils/diffing/resolveHashOrRefToCommit.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as Git from 'nodegit';
import { Commit, Oid, Reference, Repository } from 'nodegit';

export async function resolveHashOrRefToCommit(
repo: Git.Repository,
repo: Repository,
compareOidOrRefName: string
): Promise<Git.Commit> {
let oid: Git.Oid;
): Promise<Commit> {
let oid: Oid;
try {
oid = Git.Oid.fromString(compareOidOrRefName);
oid = Oid.fromString(compareOidOrRefName);
} catch {
oid = await Git.Reference.nameToId(repo, compareOidOrRefName);
oid = await Reference.nameToId(repo, compareOidOrRefName);
}
return await Git.Commit.lookup(repo, oid);
return await Commit.lookup(repo, oid);
}

0 comments on commit 835e7af

Please sign in to comment.