You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5a3c558
Browse filesBrowse the repository at this point in the historyBrowse files
authored
fix(repos): give create_or_update_file callers a SHA they can actually get (#3131)
* fix(repos): give create_or_update_file callers a SHA they can actually get
The create_or_update_file tool description and both of its SHA errors told
the caller to run `git rev-parse <branch>:<path>`. The caller is an MCP
client talking to the GitHub API, and the same description tells it not to
use this tool for local file operations, so it has no working tree to run
that command against.
Point the description at get_file_contents instead, which returns the blob
SHA over the API. In the already-exists error the server has just fetched
the file, so return that SHA directly rather than asking for a round trip.
The stale-SHA error already interpolates the current SHA, so it only needed
the impossible instruction removed.
* fix(repos): stop disclosing the blob SHA when no sha was supplied
The already-exists path is reached only when the caller sent no sha, so
it has not read the file. Returning the current blob SHA there let it
overwrite content it never saw on the next call, which is the race the
SHA gate exists to prevent. Send the caller to get_file_contents for the
path and ref instead, so obtaining the SHA still requires reading the
file.
The stale-SHA path is unaffected: the caller did supply a sha, and that
message already reported the current SHA before this change. Only its
recovery step moved off git rev-parse, and it is now imperative rather
than conditional, since a stale SHA means the file definitely changed.
Assert the already-exists error does not contain the blob SHA so the
gate cannot be loosened again without a test failing.
* fix(repos): make SHA recovery guidance actionable
Map create_or_update_file branch arguments to get_file_contents ref arguments, identify where the requested path SHA is returned, and cover symlink, branch, and API error behavior.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Dylan Pulver <dylanpulver@users.noreply.github.com>
Co-authored-by: Sam Morrow <info@sam-morrow.com>
Co-authored-by: Sam Morrow <sammorrowdrums@github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1272,7 +1272,7 @@ The following sets of tools are available:
1272
1272
-`owner`: Repository owner (username or organization) (string, required)
1273
1273
-`path`: Path where to create/update the file (string, required)
1274
1274
-`repo`: Repository name (string, required)
1275
-
-`sha`: The blob SHA of the file being replaced. Required if the file already exists. (string, optional)
1275
+
-`sha`: The blob SHA of the file being replaced. Required if the file already exists. Retrieve it with get_file_contents using the same owner, repo, and path, with ref set to this tool's branch value. (string, optional)
Copy file name to clipboardExpand all lines: pkg/github/__toolsnaps__/create_or_update_file.snap
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
"readOnlyHint": false,
5
5
"title": "Create or update file"
6
6
},
7
-
"description": "Create or update a single file in a GitHub repository. \nIf updating, you should provide the SHA of the file you want to update. Use this tool to create or update a file in a GitHub repository remotely; do not use it for local file operations.\n\nIn order to obtain the SHA of original file version before updating, use the following git command:\ngit rev-parse \u003cbranch\u003e:\u003cpath to file\u003e\n\nSHA MUST be provided for existing file updates.\n",
7
+
"description": "Create or update a single file in a GitHub repository. \nIf updating, you should provide the SHA of the file you want to update. Use this tool to create or update a file in a GitHub repository remotely; do not use it for local file operations.\n\nTo obtain the current blob SHA before updating, call the get_file_contents tool with the same owner, repo, and path, and set its ref parameter to this tool's branch value. The first text result reports the blob SHA for the requested path.\n\nSHA MUST be provided for existing file updates.\n",
8
8
"inputSchema": {
9
9
"properties": {
10
10
"allow_symlink_write": {
@@ -37,7 +37,7 @@
37
37
"type": "string"
38
38
},
39
39
"sha": {
40
-
"description": "The blob SHA of the file being replaced. Required if the file already exists.",
40
+
"description": "The blob SHA of the file being replaced. Required if the file already exists. Retrieve it with get_file_contents using the same owner, repo, and path, with ref set to this tool's branch value.",
Description: t("TOOL_CREATE_OR_UPDATE_FILE_DESCRIPTION", `Create or update a single file in a GitHub repository.
413
413
If updating, you should provide the SHA of the file you want to update. Use this tool to create or update a file in a GitHub repository remotely; do not use it for local file operations.
414
414
415
-
In order to obtain the SHA of original file version before updating, use the following git command:
416
-
git rev-parse <branch>:<path to file>
415
+
To obtain the current blob SHA before updating, call the get_file_contents tool with the same owner, repo, and path, and set its ref parameter to this tool's branch value. The first text result reports the blob SHA for the requested path.
417
416
418
417
SHA MUST be provided for existing file updates.
419
418
`),
@@ -450,7 +449,7 @@ SHA MUST be provided for existing file updates.
450
449
},
451
450
"sha": {
452
451
Type: "string",
453
-
Description: "The blob SHA of the file being replaced. Required if the file already exists.",
452
+
Description: "The blob SHA of the file being replaced. Required if the file already exists. Retrieve it with get_file_contents using the same owner, repo, and path, with ref set to this tool's branch value.",
454
453
},
455
454
"allow_symlink_write": {
456
455
Type: "boolean",
@@ -551,8 +550,10 @@ SHA MUST be provided for existing file updates.
551
550
ifcurrentSHA!=sha {
552
551
returnutils.NewToolResultError(fmt.Sprintf(
553
552
"SHA mismatch: provided SHA %s is stale. Current file SHA is %s. "+
554
-
"Pull the latest changes and use git rev-parse %s:%s to get the current SHA.",
555
-
sha, currentSHA, branch, path)), nil, nil
553
+
"The file changed since you read it. Call get_file_contents with owner=%q, repo=%q, path=%q, and ref=%q; "+
554
+
"its first text result reports the blob SHA for the requested path. "+
555
+
"Rebuild your content against what it returns, and retry with the sha parameter set to the SHA that call reports.",
0 commit comments