Developer

Git API

Read git status, log, and branches from your custom resource.

Git API

The Git API provides read-only access to the project’s git repository. Use it to check the working tree status, browse commit history, list branches, and view file diffs.

Capability required: git:read

Frontend (iframe)

import { createResourceClient } from "@rightplace/sdk";

const rp = createResourceClient();
await rp.ready();

// Get current git status
const status = await rp.git.status();
// -> { initialized: true, branch: "main", changedFiles: 3, ahead: 1, ... }

// Get recent commits
const commits = await rp.git.log(20);
// -> [{ hash: "abc123", message: "Fix bug", author: "Jane", timestamp: 1713000000, ... }]

// List branches
const branches = await rp.git.branches();
// -> [{ name: "main", isCurrent: true }, { name: "feature/new-ui", isCurrent: false }]

// Get diff for a specific file
const diff = await rp.git.diff("src/index.ts");
// -> unified diff string

Backend (Node.js)

import { createResourceServer } from "@rightplace/sdk/server";

const server = createResourceServer({
  methods: {
    getRepoSummary: async (_params, { rp }) => {
      const status = await rp.git.status();
      const branches = await rp.git.branches();
      return {
        branch: status.branch,
        changedFiles: status.changedFiles,
        branchCount: branches.length,
        hasRemote: status.hasRemote,
      };
    },
  },
});

server.start();

API Reference

rp.git.status()

Returns the current git working tree status.

ParameterTypeDescription
ReturnsPromise<GitStatus>Repository status

rp.git.log(limit?)

Returns recent commits from the current branch.

ParameterTypeDescription
limitnumberMax commits to return (default: 50)
ReturnsPromise<GitCommitEntry[]>Commit list

rp.git.branches()

Returns all local branches.

ParameterTypeDescription
ReturnsPromise<GitBranchEntry[]>Branch list

rp.git.diff(filePath)

Returns a unified diff for a specific file.

ParameterTypeDescription
filePathstringPath relative to project root
ReturnsPromise<string>Unified diff

GitStatus

FieldTypeDescription
initializedbooleanWhether git is initialized
hasRemotebooleanWhether a remote is configured
remoteUrlstring | nullRemote origin URL
branchstring | nullCurrent branch name
changedFilesnumberNumber of changed files
untrackedFilesnumberNumber of untracked files
commitCountnumberTotal commits on current branch
aheadnumberCommits ahead of remote
behindnumberCommits behind remote
changedFilePathsGitFileEntry[]Changed file details

GitCommitEntry

FieldTypeDescription
hashstringFull commit hash
shortHashstringAbbreviated hash
messagestringCommit message
authorstringAuthor name
timestampnumberUnix timestamp
parentHashesstring[]Parent commit hashes

GitBranchEntry

FieldTypeDescription
namestringBranch name
isCurrentbooleanWhether this is the active branch

GitFileEntry

FieldTypeDescription
pathstringFile path
statusstringStatus (e.g. “modified”, “added”, “deleted”)
stagedbooleanWhether the change is staged

Manifest Configuration

{
  "capabilities": [
    "git:read"
  ]
}

Notes

  • This API is read-only. Resources cannot commit, push, pull, or modify the git repository.
  • The project must have a folder path set and contain a .git directory.
  • Diff output uses standard unified diff format.