Sourcegraph DocsSourcegraph Docs
  • Code Intelligence

    • Cody
    • Code Search
  • Code Management

    • Batch Changes
    • Code Navigation
    • Code Monitoring
    • Code Ownership
    • Code Insights
    • Notebooks
  • Platform

    • Sourcegraph Admin
    • Sourcegraph Cloud
    • Integrations
    • Development
  • CLI & API

    • Sourcegraph CLI
    • Sourcegraph GraphQL API
    • Sourcegraph Stream API
  • Help & Support

    • SLAs & Premium Support
    • Tutorials
    • Sourcegraph Accounts
    • Changelog
  1. Docs
  2. dev
  3. background-information
  4. gitserver-api

gitserver API

As of February 1, 2023

gitserver is Sourcegraph's interface to Git repositories. It clones repositories and exposes an API for interacting with that clone.

gitserver used to expose a simple "run any Git command" interface, but that was removed. and in its place the gitserver client exposes an API supporting specific Git operations.

MethodDescriptionNotesGit Command or GitServer Endpoint
AddrForReporesolves repo names to gitserver instances
Addrsreturns addresses for gitserver instances
ArchiveReaderdownload archived repository
BatchLogallows for monitoring and aborting the applying of batch changesgit log -n 1 --name-only
BlameFilereturns git blame information about a filegit blame
StreamBlameFileSame as BlameFile, but streaminggit blame
BranchesContainingReturns all of the branches containing the given commitgit branch --contains <commit> --format %(refname)
CommitDatereturns the time the given commit was committedDoes not error if commit DNE, but returns a false value flaggit show -s --format=%H:%cI
CommitExistsdetermines if the given commit exists in the given repositoryDoes not error if commit DNE, but returns a false value flaggit log --format=format:%H%x00%aN%x00%aE%x00%at%x00%cN%x00%cE%x00%ct%x00%B%x00%P%x00 -n 1 <commit hash>
CommitGraphreturns the commit graph for the given repository as a mapping from a commit to its parentsruns git log --pretty="%H %P" --topo-order with either --all --since, or -### with a numeric limit
Commitsreturns all commits matching the optionsruns git log --pretty="%H %P" --topo-order with either --all --since, or -### with a numeric limit, and filters them based on supplied options, such as author, message, before, after, etc...
CommitsExistdetermines if the given commits exist in the given repositoriesUses GetCommits
CommitsUniqueToBranchreturns a map from commits that exist on a given branch in the given repository to their commit dateruns git log --pretty=format:%H:%cI with other options depending on parameters
ContributorCountreturns the number of commits grouped by contributorruns git shortlog -s -n -e --no-merges with other options depending on parameters
CreateCommitFromPatchCreates a commit from a patch file (optionally pushing it to origin?)clones the repo to a temp dir, then runs git apply on the patch.
Diffreturns an iterator that can be used to access the diff between two commits on a per-file basiscomment on the method mentions go-diff which might be useful to look intogit diff --find-renames --full-index --inter-hunk-context=3 --no-prefix <range> --
DiffPathreturns the changes to a given path between the given source and target commitsreturns one diff even if there are multiple commits in between the two given commitsgit diff <from commit> <to commit> -- <path>
DiffSymbolsperforms a diff command which is expected to be parsed by our symbols packagegit diff -z --name-status --no-renames <from commit> <to commit>
FirstEverCommitreturns the first commit ever made to the repositoryruns git rev-list --reverse --date-order --max-parents=0 HEAD to get the commit hash, then calls GetCommit with the hash
GetBehindAheadreturns the behind/ahead commit counts information for right vs. left (both Git revspecs)git rev-list --count --left-right <left commit>...<right commit>
GetCommitreturns the commit with the given commit IDerrors if no such commit existsgit log -n 1 <commit>
GetCommitsreturns a git commit object describing each of the given repository and commit pairsUses the batch log interfacegit log -n 1 --name-only
GetDefaultBranchReturns the default branch name and current commit"default" means "current" in the implementation, probably because all of the indexing work in a repository is done in the default branch?git symbolic-ref HEAD
GetObjectReturns a Git Object, which is one of "commit", "tag", "tree" or "blob"I'm not clear on the use cases for this methoduses git rev-parse and git cat-file
HasCommitAfterreturns a boolean indicating if a repo contains a commit after a given date. Used to assess how "stale" a repository isDoes it look at the origin? Just locally?git rev-list -n 1 --after=<date> --count HEAD
Headdetermines the tip commit of the default branch for the given repositoryruns git rev-parse HEAD to get the commit hash, then uses GetCommit
IsRepoCloneablereturns an error if a repo is not cloneable
ListBranchesReturns a list of all of the branches in the repositoryIncludes information about the HEAD commit, and how many commits the branch is beind and ahead of another given branch.git branch
ListDirectoryChildrenfetches the list of children under the given directory namesSeems to be NOT recursive? Returns strings, not Git Objects.git ls-tree --name-only <commit id> -- <dirname> ...
ListFilesreturns a list of root-relative file paths matching the given pattern in a particular commit of a repositoryThis one is recursive - uses the -r option.git ls-tree --name-only -r <commit id> -- and then filtering returned paths by a given regular expression
ListRefsReturns a list of references in a repositoryreferences are human-friendly names for commit hashes. For example, git checkout -b mybranch creates a reference named "mybranch" pointed to the current HEAD hash. References are files stored in .git/refs. What's the use case for this? Is it mainly/only for display so an end user can click on a particular reference and will be taken to that target?git show-ref
ListTagsreturns a list of all tags in the repository. If commitObjs is non-empty, only all tags pointing at those commits are returned.git tag --list --sort --creatordate --format %(if)%(\*objectname)%(then)%(\*objectname)%(else)%(objectname)%(end)%00%(refname:short)%00%(if)%(creatordate:unix)%(then)%(creatordate:unix)%(else)%(\*creatordate:unix)%(end)
LsFilesreturns the output of git ls-files, null-separated, with optional path specificationsgit ls-files -z --with-tree <commit id> -- <path> ...
MergeBasereturns the common ancestor for a merge of two given commitsgit merge-base
NewFileReaderreads from the given file at the given commitgit show <commit>:<path>
P4Execsends a p4 command and reads the outputAccesses the /p4-exec endpoint of gitserver, which according to the comments, "is currently only used for fetching user based permissions information so, we don't have a repo name"Doesn't do any Git commands; runs p4 with the given command
ReadDirreads the given directory at the given committhe comment on --long is, "show size"git ls-tree --long --full-name -z <commit> (-r -t)? (-- <path>)?
ReadFileLike NewFileReader, but returns a byte slize instead of a readeruses NewFileReader internallygit show <commit>:<path>
RefDescriptionsreturns a map from commits to descriptions of the tip of each branch and tag of the given repositoryreturns the struct:
- the name of the branch/tag
- the type (unknown, branch, or tag)
- true/false for default (current) branch
- date branch/tag created
git for-each-ref --format="%(if)%(\*objectname)%(then)%(\*objectname)%(else)%(objectname)%(end)%(refname)%(HEAD)%(if)%(\*creatordate:iso8601-strict)%(then)%(\*creatordate:iso8601-strict)%(else)%(creatordate:iso8601-strict)%(end)%00" refs/heads/ refs/tags/ --points-at=<commit>
Removeremoves the repository clone from gitserverlooks up the instance and calls RemoveFrom with that instance
RemoveFromremoves the repository clone from the given gitserver
RepoCloneProgresscalls gitserver's /repo-clone-progress endpointReturns the output of the clone commandchecks on the existance of GIT_DIR and if it's still locked by a clone process
RequestRepoClonean asynchronous request to clone a repositorycalls gitserver's /repo-clone endpointgit clone
RequestRepoUpdatecalls gitserver's /repo-update endpoint
ResolveRevisionreturns the absolute commit for a commit-ish specgit rev-parse <commit-ish spec>
ResolveRevisionsexpands a set of RevisionSpecifiers (which may include hashes, globs, refs, or glob exclusions) into an equivalent set of commit hashesgit rev-parse <commit-ish spec> ...
Statreturns a FileInfo describing the named file at commitmaps output from git ls-tree into FileInfo structs, with the object hash in the Sys_ member
IsPerforcePathCloneablecheck if a given depot/depot path is cloneable with the given credentialscalls gitserver's /is-perforce-path-cloneable endpoint
CheckPerforceCredentialscheck if a given Perforce credential is validcalls gitserver's /check-perforce-credentials endpoint
PerforceUserslist all perforce userscalls gitserver's /perforce-users endpoint
PerforceProtectsForUserlist all protections that apply to a usercalls gitserver's /perforce-protects-for-user endpoint
PerforceProtectsForDepotlist all protections that apply to a depotcalls gitserver's /perforce-protects-for-depot endpoint
PerforceGroupMemberslist all members of a Perforce groupcalls gitserver's /perforce-group-members endpoint
IsPerforceSuperUsercheck if a given ticket is for a super level usercalls gitserver's /is-perforce-super-user endpoint
PerforceGetChangelistget details about a perforce changelistcalls gitserver's /perforce-get-changelist endpoint

On this page

  1. gitserver API