import{execSync}from"../cmd";import{Path}from"../path";importRepoFilefrom"./repofile";/** * a git repository is a directory with a .git subdirectory * This is basically a git porcelain that keeps the current repo */classRepo{// the full path to the repository// this is the directory that contains the .git subdirectorypublicpath: Path;constructor(path: Path){this.path=path;}staticcreate(sourcePath: Path){returnnewRepo(sourcePath);}/** * Get a reference to the git repo's file at the provided path. * @param atPath * @returns */getFile(atPath: Path){if(!this.path.contains(atPath)){thrownewError(`File ${atPath} is not in the repository`);}returnRepoFile.create(this,atPath);}/** * Run a command from this git repository's root. */runCmd(command: string){constcmdResult=execSync(command,{cwd: this.path.toString()});returncmdResult.toString();}checkout(branchName: string){returnthis.runCmd(`git checkout ${branchName}`);}addAll(){console.log("adding all to git");this.runCmd("git add .");}commit(message="robot commit"){console.log("committing",{ message });this.runCmd(`git -c commit.gpgsign=false commit -m "${message}"`);}push(){this.runCmd("git push");}removeUntracked(){this.runCmd("git clean -fxd");}currentBranch(){constbranch=this.runCmd("git branch --show-current");console.log("current branch",branch);returnbranch;}status(){conststatus=this.runCmd("git status");console.log(status);}stash(){this.runCmd("git stash");}stashPop(){this.runCmd("git stash pop");}}exportdefaultRepo;