How to use the isomorphic-git.currentBranch function in isomorphic-git

To help you get started, weโ€™ve selected a few isomorphic-git examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mizchi / next-editor / src / domain / git / queries / getProjectGitStatus.ts View on Github external
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,
github adobe / helix-cli / src / git-utils.js View on Github external
static async getBranch(dir) {
    // current branch name
    const currentBranch = await git.currentBranch({ dir, fullname: false });
    // current commit sha
    const rev = await git.resolveRef({ dir, ref: 'HEAD' });
    // reverse-lookup tag from commit sha
    const allTags = await git.listTags({ dir });

    const tagCommitShas = await Promise.all(allTags.map(async (tag) => {
      const oid = await git.resolveRef({ dir, ref: tag });
      const obj = await git.readObject({ dir, oid });
      // annotated or lightweight tag?
      return obj.type === 'tag' ? {
        tag,
        sha: await git.resolveRef({ dir, ref: obj.object.object }),
      } : { tag, sha: oid };
    }));
    const tag = tagCommitShas.find((entry) => entry.sha === rev);
    return typeof tag === 'object' ? tag.tag : currentBranch;
github felipemanga / FemtoIDE / plugins / git.js View on Github external
onOpenProject(){
            dir = DATA.projectPath;
            if( !fs.existsSync(dir + path.sep + ".git") ){
                noGit = true;
                return;
                git.init({dir}).then(result=>{
                    log("New git initialized");
                    wasInit = true;
                }).catch(ex=>{
                    log("Error initializing git: " + ex);
                });
            }else{
                wasInit = true;
                git.currentBranch({dir, fullname:false})
                    .then(name=>log(`Currently on branch ${name}`));
            }
        }
    });
github mizchi / next-editor / src / domain / git / queries / getBranchStatus.ts View on Github external
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,
github CleverCloud / clever-tools / src / models / git.js View on Github external
async function getFullBranch (branchName) {
  const repo = await getRepo();
  if (branchName === '') {
    return git.currentBranch({ ...repo, fullname: true });
  }
  return git.expandRef({ ...repo, ref: branchName });
};
github mizchi / next-editor / src / lib / repository.ts View on Github external
return { ...acc, unmodified: [...acc.unmodified, fileStatus.relpath] }
        }
        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
  }
}