> ## Documentation Index
> Fetch the complete documentation index at: https://docs.relace.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Repo

> Update repo content with files or sync from Git.

## Path Parameters

<ParamField path="repo_id" type="string" required>
  Repo ID
</ParamField>

## Request Body

<ParamField body="source" type="object">
  Optional source for updating the repo content

  <Expandable title="properties" defaultOpen={false}>
    {' '}

    <ParamField body="type" type="string" required>
      Update type: `"git"` for Git sync, `"files"` to replace all repo content, or
      `"diff"` for specific operations
    </ParamField>

    <Tabs>
      <Tab title="Git">
        <ParamField body="url" type="string" required>
          Git repo URL to sync from
        </ParamField>

        <ParamField body="branch" type="string">
          Specific branch to sync (optional)
        </ParamField>
      </Tab>

      <Tab title="Files">
        <ParamField body="files" type="array" required>
          Array of file objects that will completely replace the repo content. Any files not included will be deleted from the repo.

          <Expandable title="properties" defaultOpen={false}>
            <ParamField body="filename" type="string" required>
              The path and filename for the file
            </ParamField>

            <ParamField body="content" type="string" required>
              The content of the file
            </ParamField>
          </Expandable>
        </ParamField>
      </Tab>

      <Tab title="Diff">
        <ParamField body="operations" type="array" required>
          Array of file operations to perform

          <Expandable title="properties" defaultOpen={false}>
            <ParamField body="type" type="string" required>
              Operation type: `"write"` to create/update, `"rename"` to change filename, or `"delete"` to remove

              <Expandable title="operation-specific properties" defaultOpen={false}>
                <Tabs>
                  <Tab title="Write">
                    <ParamField body="filename" type="string" required>
                      The path and filename for the file
                    </ParamField>

                    <ParamField body="content" type="string" required>
                      The content of the file
                    </ParamField>
                  </Tab>

                  <Tab title="Rename">
                    <ParamField body="old_filename" type="string" required>
                      The current path and filename
                    </ParamField>

                    <ParamField body="new_filename" type="string" required>
                      The new path and filename
                    </ParamField>
                  </Tab>

                  <Tab title="Delete">
                    <ParamField body="filename" type="string" required>
                      The path and filename to delete
                    </ParamField>
                  </Tab>
                </Tabs>
              </Expandable>
            </ParamField>
          </Expandable>
        </ParamField>
      </Tab>
    </Tabs>
  </Expandable>
</ParamField>

<ParamField body="metadata" type="object">
  Optional object containing any key-value pairs, which overwrites any existing
  metadata.
</ParamField>

<Info>
  If neither `source` nor `metadata` is provided, you'll receive a 422 error.
</Info>

## Response

<ResponseField name="repo_id" type="string">
  The repository ID that was updated
</ResponseField>

<ResponseField name="repo_head" type="string">
  Commit hash for the updated repo head
</ResponseField>

<ResponseField name="changed_files" type="array">
  Array of file paths that were modified
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.relace.run/v1/repo/123e4567-e89b-12d3-a456-426614174000/update \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "source": {
        "type": "diff",
        "operations": [
          {
            "type": "write",
            "filename": "src/search.ts",
            "content": "function findItem(array: Item[], targetId: string): Item | undefined {\n  for (let i = 0; i < array.length; i++) {\n    const item = array[i];\n    if (item.id === targetId) {\n      return item;\n    }\n  }\n  return undefined;\n}"
          },
          {
            "type": "rename",
            "old_filename": "src/utils.ts",
            "new_filename": "src/helpers.ts"
          },
          {
            "type": "delete",
            "filename": "old-file.js"
          }
        ]
      },
      "metadata": {
        "version": "2.1.0",
        "updated_by": "user123"
      }
    }'
  ```

  ```typescript TypeScript SDK theme={null}
  import { Relace } from "@relace-ai/relace";

  const client = new Relace({ apiKey: "YOUR_API_KEY" });

  const repoId = "123e4567-e89b-12d3-a456-426614174000";

  const result = await client.repo.update(repoId, {
      source: {
          type: "diff",
          operations: [
              {
                  type: "write",
                  filename: "src/search.ts",
                  content: "function findItem(array: Item[], targetId: string): Item | undefined {\n  for (let i = 0; i < array.length; i++) {\n    const item = array[i];\n    if (item.id === targetId) {\n      return item;\n    }\n  }\n  return undefined;\n}"
              },
              {
                  type: "rename",
                  old_filename: "src/utils.ts",
                  new_filename: "src/helpers.ts"
              },
              {
                  type: "delete",
                  filename: "old-file.js"
              }
          ]
      },
      metadata: {
          version: "2.1.0",
          updated_by: "user123"
      }
  });

  console.log(result);
  ```

  ```python Python SDK theme={null}
  from relace import Relace

  client = Relace(api_key="YOUR_API_KEY")

  repo_id = "123e4567-e89b-12d3-a456-426614174000"

  data = client.repo.update(
      repo_id,
      source={
          "type": "diff",
          "operations": [
              {
                  "type": "write",
                  "filename": "src/search.ts",
                  "content": (
                      "function findItem(array: Item[], targetId: string): Item | undefined {\n"
                      "  for (let i = 0; i < array.length; i++) {\n"
                      "    const item = array[i];\n"
                      "    if (item.id === targetId) {\n"
                      "      return item;\n"
                      "    }\n"
                      "  }\n"
                      "  return undefined;\n"
                      "}"
                  ),
              },
              {
                  "type": "rename",
                  "old_filename": "src/utils.ts",
                  "new_filename": "src/helpers.ts",
              },
              {
                  "type": "delete",
                  "filename": "old-file.js",
              },
          ],
      },
      metadata={
          "version": "2.1.0",
          "updated_by": "user123",
      },
  )

  print(data)
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "repo_head": "abc123def456",
    "repo_id": "123e4567-e89b-12d3-a456-426614174000",
    "changed_files": ["src/search.ts", "src/helpers.ts", "old-file.js"]
  }
  ```
</ResponseExample>
