repos.commits.createFromDiff
Create a commit by streaming a Git patch instead of individual file blobs. Use this when your workflow already produces unified diffs or generated patches.
Scope: git:write on the repository.
import { Pierre } from '@pierre/sdk';
// The client reads PIERRE_ORG and PIERRE_PRIVATE_KEY.
const pierre = new Pierre();
const result = await pierre.repos.commits.createFromDiff({
repo_name: 'my-demo-repository',
author: { email: 'diff@example.com', name: 'Diff Bot' },
commit_message: 'Apply generated patch',
expected_target_sha: 'd34db33fd34db33fd34db33fd34db33fd34db33f',
target_branch: 'main',
diff: 'diff --git a/README.md b/README.md\n@@ -1,1 +1,2 @@\n-Hello\n+Hello World\n',
});
console.log(result);from pierre import Pierre
# The client reads PIERRE_ORG and PIERRE_PRIVATE_KEY.
pierre = Pierre()
result = pierre.repos.commits.create_from_diff(
repo_name="my-demo-repository",
author={"email": "diff@example.com", "name": "Diff Bot"},
commit_message="Apply generated patch",
expected_target_sha="d34db33fd34db33fd34db33fd34db33fd34db33f",
target_branch="main",
diff="diff --git a/README.md b/README.md\n@@ -1,1 +1,2 @@\n-Hello\n+Hello World\n",
)
print(result)import (
"context"
"fmt"
"strings"
pierre "github.com/pierrecomputer/sdk/go"
)
ctx := context.Background()
// The client reads PIERRE_ORG and PIERRE_PRIVATE_KEY.
client, err := pierre.NewClient()
if err != nil {
return err
}
result, err := client.Repos.Commits.CreateFromDiff(ctx, pierre.ReposCommitsCreateFromDiffParams{
RepoName: "my-demo-repository",
Author: pierre.GitIdentity{Email: "diff@example.com", Name: "Diff Bot"},
CommitMessage: "Apply generated patch",
ExpectedTargetSHA: pierre.String("d34db33fd34db33fd34db33fd34db33fd34db33f"),
TargetBranch: "main",
Diff: strings.NewReader("diff --git a/README.md b/README.md\n@@ -1,1 +1,2 @@\n-Hello\n+Hello World\n"),
})
if err != nil {
return err
}
fmt.Println(result)pierre repos:commits create-from-diff \
--repo-name my-demo-repository \
--author.email diff@example.com \
--author.name 'Diff Bot' \
--commit-message 'Apply generated patch' \
--expected-target-sha d34db33fd34db33fd34db33fd34db33fd34db33f \
--target-branch main \
--diff - <<'EOF'
diff --git a/README.md b/README.md
@@ -1,1 +1,2 @@
-Hello
+Hello World
EOFcurl -X POST \
"https://api.{org}.code.storage/api/repos/my-demo-repository/diff-commit" \
-H "Authorization: Bearer $PIERRE_TOKEN" \
-H "Content-Type: application/x-ndjson" \
--data-binary @- <<'EOF'
{"metadata":{"author":{"email":"diff@example.com","name":"Diff Bot"},"commit_message":"Apply generated patch","expected_target_sha":"d34db33fd34db33fd34db33fd34db33fd34db33f","target_branch":"main"}}
{"diff_chunk":{"data":"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=","eof":false}}
{"diff_chunk":{"data":"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK","eof":true}}
EOF{
"commit": {
"blob_count": 1,
"commit_sha": "<string>",
"pack_bytes": 1,
"target_branch": "<string>",
"tree_sha": "<string>"
},
"result": {
"branch": "<string>",
"new_sha": "<string>",
"old_sha": "<string>",
"status": "ok",
"success": true,
"target_branch": "<string>",
"message": "<string>"
}
}{
"commit": null,
"result": {
"message": "diff content missing",
"new_sha": "",
"old_sha": "",
"status": "invalid",
"success": false,
"target_branch": ""
}
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"commit": {
"blob_count": 1,
"commit_sha": "7b3e9f2a1c4d5e6f708192a3b4c5d6e7f8091a2b",
"pack_bytes": 1024,
"target_branch": "main",
"tree_sha": "e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4"
},
"result": {
"message": "failed to update ref",
"new_sha": "7b3e9f2a1c4d5e6f708192a3b4c5d6e7f8091a2b",
"old_sha": "d34db33fd34db33fd34db33fd34db33fd34db33f",
"status": "failed",
"success": false,
"target_branch": "main"
}
}{
"commit": null,
"result": {
"message": "no changes to commit",
"new_sha": "",
"old_sha": "",
"status": "precondition_failed",
"success": false,
"target_branch": ""
}
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"commit": null,
"result": {
"message": "upstream Git server request failed; the push may or may not have been applied, check the branch before retrying",
"new_sha": "",
"old_sha": "",
"status": "internal",
"success": false,
"target_branch": ""
}
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}Authorizations
JWT bearer token signed with your organization's registered signing key. There is no OAuth authorization server; you mint tokens yourself and the token's scopes claim carries the granted permission scopes. Public scopes: git:read (read repository contents), git:write (write branches, commits, tags, and notes), repo:write (create and manage repositories), org:read (list an organization's repositories). Each operation's security requirement names the scopes it requires. See https://code.storage/docs/getting-started/authentication for how to mint tokens.
Path Parameters
The repository name, for example acme/web.
Body
Send newline-delimited JSON where the first line is a metadata object and each following line is a diff_chunk. The combined diff must be compatible with git apply --cached --binary.
NDJSON stream. The first line must be metadata; subsequent lines must be diff_chunk payloads. Decoded diff chunks are limited to 4 MiB each.
Response
Commit created from the supplied diff.
import { Pierre } from '@pierre/sdk';
// The client reads PIERRE_ORG and PIERRE_PRIVATE_KEY.
const pierre = new Pierre();
const result = await pierre.repos.commits.createFromDiff({
repo_name: 'my-demo-repository',
author: { email: 'diff@example.com', name: 'Diff Bot' },
commit_message: 'Apply generated patch',
expected_target_sha: 'd34db33fd34db33fd34db33fd34db33fd34db33f',
target_branch: 'main',
diff: 'diff --git a/README.md b/README.md\n@@ -1,1 +1,2 @@\n-Hello\n+Hello World\n',
});
console.log(result);from pierre import Pierre
# The client reads PIERRE_ORG and PIERRE_PRIVATE_KEY.
pierre = Pierre()
result = pierre.repos.commits.create_from_diff(
repo_name="my-demo-repository",
author={"email": "diff@example.com", "name": "Diff Bot"},
commit_message="Apply generated patch",
expected_target_sha="d34db33fd34db33fd34db33fd34db33fd34db33f",
target_branch="main",
diff="diff --git a/README.md b/README.md\n@@ -1,1 +1,2 @@\n-Hello\n+Hello World\n",
)
print(result)import (
"context"
"fmt"
"strings"
pierre "github.com/pierrecomputer/sdk/go"
)
ctx := context.Background()
// The client reads PIERRE_ORG and PIERRE_PRIVATE_KEY.
client, err := pierre.NewClient()
if err != nil {
return err
}
result, err := client.Repos.Commits.CreateFromDiff(ctx, pierre.ReposCommitsCreateFromDiffParams{
RepoName: "my-demo-repository",
Author: pierre.GitIdentity{Email: "diff@example.com", Name: "Diff Bot"},
CommitMessage: "Apply generated patch",
ExpectedTargetSHA: pierre.String("d34db33fd34db33fd34db33fd34db33fd34db33f"),
TargetBranch: "main",
Diff: strings.NewReader("diff --git a/README.md b/README.md\n@@ -1,1 +1,2 @@\n-Hello\n+Hello World\n"),
})
if err != nil {
return err
}
fmt.Println(result)pierre repos:commits create-from-diff \
--repo-name my-demo-repository \
--author.email diff@example.com \
--author.name 'Diff Bot' \
--commit-message 'Apply generated patch' \
--expected-target-sha d34db33fd34db33fd34db33fd34db33fd34db33f \
--target-branch main \
--diff - <<'EOF'
diff --git a/README.md b/README.md
@@ -1,1 +1,2 @@
-Hello
+Hello World
EOFcurl -X POST \
"https://api.{org}.code.storage/api/repos/my-demo-repository/diff-commit" \
-H "Authorization: Bearer $PIERRE_TOKEN" \
-H "Content-Type: application/x-ndjson" \
--data-binary @- <<'EOF'
{"metadata":{"author":{"email":"diff@example.com","name":"Diff Bot"},"commit_message":"Apply generated patch","expected_target_sha":"d34db33fd34db33fd34db33fd34db33fd34db33f","target_branch":"main"}}
{"diff_chunk":{"data":"ZGlmZiAtLWdpdCBhL1JFQURNRS5tZCBiL1JFQURNRS5tZAo=","eof":false}}
{"diff_chunk":{"data":"QEAgLTEsMSArMSwyIEBACi1IZWxsbworSGVsbG8gV29ybGQK","eof":true}}
EOF{
"commit": {
"blob_count": 1,
"commit_sha": "<string>",
"pack_bytes": 1,
"target_branch": "<string>",
"tree_sha": "<string>"
},
"result": {
"branch": "<string>",
"new_sha": "<string>",
"old_sha": "<string>",
"status": "ok",
"success": true,
"target_branch": "<string>",
"message": "<string>"
}
}{
"commit": null,
"result": {
"message": "diff content missing",
"new_sha": "",
"old_sha": "",
"status": "invalid",
"success": false,
"target_branch": ""
}
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"commit": {
"blob_count": 1,
"commit_sha": "7b3e9f2a1c4d5e6f708192a3b4c5d6e7f8091a2b",
"pack_bytes": 1024,
"target_branch": "main",
"tree_sha": "e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4"
},
"result": {
"message": "failed to update ref",
"new_sha": "7b3e9f2a1c4d5e6f708192a3b4c5d6e7f8091a2b",
"old_sha": "d34db33fd34db33fd34db33fd34db33fd34db33f",
"status": "failed",
"success": false,
"target_branch": "main"
}
}{
"commit": null,
"result": {
"message": "no changes to commit",
"new_sha": "",
"old_sha": "",
"status": "precondition_failed",
"success": false,
"target_branch": ""
}
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}{
"commit": null,
"result": {
"message": "upstream Git server request failed; the push may or may not have been applied, check the branch before retrying",
"new_sha": "",
"old_sha": "",
"status": "internal",
"success": false,
"target_branch": ""
}
}{
"code": "<string>",
"status": 123,
"title": "<string>",
"type": "<string>",
"detail": "<string>",
"error": "<string>",
"instance": "<string>"
}