Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function getProjectGitStatus(
projectRoot: string
): Promise {
// branching
const currentBranch = await git.currentBranch({ fs, dir: projectRoot })
const branches = await git.listBranches({ fs, dir: projectRoot })
const history = await getGitHistory(projectRoot, { ref: currentBranch })
// staging
const trackingStatus = await getGitTrackingStatus(projectRoot)
const { tracked, untracked } = trackingStatus
const {
staged,
unstaged,
unmodified,
rawStatusList
} = await getFileStatusInProject(projectRoot, tracked)
return {
rawStatusList,
unstaged,
export async function listRemoteBranches(
projectRoot: string,
remote: string
): Promise {
try {
const branches: string[] = await git.listBranches({
dir: projectRoot,
remote
})
return branches.map(b => `remotes/${remote}/${b}`)
} catch (e) {
// TODO: Check remote fetched once
return []
}
}
public async getBranchAndTags(repoUri: string): Promise {
const gitdir = this.repoDir(repoUri);
const remoteBranches = await isogit.listBranches({ gitdir, remote: 'origin' });
const results: ReferenceInfo[] = [];
for (const name of remoteBranches) {
const reference = `refs/remotes/origin/${name}`;
const commit = await this.getCommitInfo(repoUri, reference);
if (commit) {
results.push({
name,
reference,
type: ReferenceType.REMOTE_BRANCH,
commit,
});
}
}
const tags = await isogit.listTags({ gitdir });
for (const name of tags) {
const reference = `refs/tags/${name}`;
}
default: {
return acc
}
}
},
{
added: [],
modified: [],
staged: [],
unmodified: []
}
)
const currentBranch = await git.currentBranch({ fs, dir: projectRoot })
const branches = await git.listBranches({ fs, dir: projectRoot })
const history = await getLogInRepository(projectRoot, { ref: currentBranch })
return {
branches,
currentBranch,
stagingStatus,
trackingStatus,
history
}
}
export function listBranches(projectRoot: string): Promise {
return git.listBranches({ fs, dir: projectRoot })
}
.then((repo) => git.listBranches(repo))
.then(autocomplete.words);
export function listBranches(
projectRoot: string,
remote: string | null = null
): Promise {
return git.listBranches({ dir: projectRoot, remote })
}
export async function getBranchStatus(
projectRoot: string
): Promise<{
currentBranch: string
branches: string[]
history: CommitDescription[]
remotes: string[]
remoteBranches: string[]
}> {
const currentBranch = await git.currentBranch({ dir: projectRoot })
const branches = await git.listBranches({ dir: projectRoot })
const remotes: string[] = (await git.listRemotes({ dir: projectRoot })).map(
(a: { remote: string; url: string }) => a.remote
)
const remoteBranches = flatten(
await Promise.all(
remotes.map(remote => listRemoteBranches(projectRoot, remote))
)
)
const history = await getHistory(projectRoot, { ref: currentBranch })
return {
currentBranch,
branches,
remotes,
remoteBranches,