threads / bug / 64661

[BUG] git restore: typo in error message "could not resolve ource"

Subject: [BUG] git restore: typo in error message "could not resolve ource"

## tl;dr

5 messages between Dec 22, 2025 and Dec 24, 2025.

replies: 4people: 3as markdown or json

Zhelyo Zhelev· Dec 22, 2025, 09:16 UTC · lore

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue) I executed the following command in repository: git restore -source my_base_branch I have reproduced this on both Windows (git version 2.52.0.windows.1) and Ubuntu (git version 2.52.0).

What did you expect to happen? (Expected behavior) The error message should be: fatal: could not resolve source

What happened instead? (Actual behavior) The error message is: fatal: could not resolve ource

What's different between what you expected and what actually happened? There is a typo in the displayed error message - the first letter 's' is missing from the word "source" in the output.

Anything else you want to add: The bug is present in the latest stable version 2.52.0 on both Linux and Windows.

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info]
git version:
git version 2.52.0.windows.1
cpu: x86_64
built from commit: 2912d8e9b8253723974b7baf1c890273b1a1c5bd
sizeof-long: 4
sizeof-size_t: 8
shell-path: D:/git-sdk-64-build-installers/usr/bin/sh
rust: disabled
feature: fsmonitor--daemon
libcurl: 8.17.0
OpenSSL: OpenSSL 3.5.4 30 Sep 2025
zlib: 1.3.1
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
default-ref-format: files
default-hash: sha1
uname: Windows 10.0 26100
compiler info: gnuc: 15.2
libc info: no libc information available
$SHELL (typically, interactive shell): <unset>
[Enabled Hooks]
brian m. carlson· Dec 22, 2025, 11:56 UTC · re: Zhelyo Zhelev · lore

Re: [BUG] git restore: typo in error message "could not resolve ource"

On 2025-12-22 at 09:16:07, Zhelyo Zhelev wrote:
Show 8 quoted lines
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
> 
> What did you do before the bug happened? (Steps to reproduce your issue)
> I executed the following command in repository: git restore -source
> my_base_branch
> I have reproduced this on both Windows (git version 2.52.0.windows.1)
> and Ubuntu (git version 2.52.0).

I can also reproduce this using Git 2.51.0.338.gd7d06c2dae8 on Debian unstable.

Show 11 quoted lines
> What did you expect to happen? (Expected behavior)
> The error message should be:
> fatal: could not resolve source
> 
> What happened instead? (Actual behavior)
> The error message is:
> fatal: could not resolve ource
> 
> What's different between what you expected and what actually happened?
> There is a typo in the displayed error message - the first letter 's'
> is missing from the word "source" in the output.

I think this is due to a typo in your command and I'll explain why it happens.

You wrote `git restore -source`, not `git restore --source`. Most programs use double dashes for long options, including Git. Part of the reason the second dash is necessary is that `-source` is interpreted as `-s ource`, or the equivalent of `--source=ource`. Git was confused because `ource` didn't match any revision it could check out and obviously that's because you didn't intend that at all.

So I think this is functioning as designed and isn't actually a typo in Git. The code appears to be in `builtin/checkout.c`:

    builtin/checkout.c:                     die(_("could not resolve %s"), opts->from_treeish);

That shows that it prints "could not resolve" and then the thing it tried to resolve as a branch.

-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Junio C Hamano· Dec 22, 2025, 13:19 UTC · re: brian m. carlson · lore

Re: [BUG] git restore: typo in error message "could not resolve ource"

"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 7 quoted lines
> So I think this is functioning as designed and isn't actually a typo in
> Git.  The code appears to be in `builtin/checkout.c`:
>
>     builtin/checkout.c:                     die(_("could not resolve %s"), opts->from_treeish);
>
> That shows that it prints "could not resolve" and then the thing it
> tried to resolve as a branch.
Hilarious.

We probably should give a pair of quotes around '%s' like other messages, and that is what CodingGuidelines asks us to do. In the section of "Error Messages", we find this.

 - Enclose the subject of an error inside a pair of single quotes,
   e.g. `die(_("unable to open '%s'"), path)`.
Thanks.
brian m. carlson· Dec 24, 2025, 20:32 UTC · re: Junio C Hamano · lore

[PATCH] checkout: quote invalid treeish in error message

We received a report that invoking "git restore -source my_base_branch" resulted in the confusing error message "fatal: could not resolve ource". This looked like a typo in our error message, but it is actually because "-source" is missing its second dash and is being resolved as "-s ource". However, due to the lack of the quoting recommended in CodingGuidelines, this is confusing to the reader and we can do better.

Add the necessary quoting to this message. With this change, we now get this less confusing message:

    fatal: could not resolve 'ource'
Reported-by: Zhelyo Zhelev <zhelyo@gmail.com>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/checkout.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 66b69df6e6..261699e2f5 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1899,7 +1899,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
 		struct object_id rev;
 
 		if (repo_get_oid_mb(the_repository, opts->from_treeish, &rev))
-			die(_("could not resolve %s"), opts->from_treeish);
+			die(_("could not resolve '%s'"), opts->from_treeish);
 
 		setup_new_branch_info_and_source_tree(&new_branch_info,
 						      opts, &rev,
Junio C Hamano· Dec 24, 2025, 23:43 UTC · re: brian m. carlson · lore

Re: [PATCH] checkout: quote invalid treeish in error message

"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 18 quoted lines
> We received a report that invoking "git restore -source my_base_branch"
> resulted in the confusing error message "fatal: could not resolve
> ource".  This looked like a typo in our error message, but it is
> actually because "-source" is missing its second dash and is being
> resolved as "-s ource".  However, due to the lack of the quoting
> recommended in CodingGuidelines, this is confusing to the reader and
> we can do better.
>
> Add the necessary quoting to this message.  With this change, we now get
> this less confusing message:
>
>     fatal: could not resolve 'ource'
>
> Reported-by: Zhelyo Zhelev <zhelyo@gmail.com>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/checkout.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
Obviously the right thing to do.  Thanks.
Show 14 quoted lines
>
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 66b69df6e6..261699e2f5 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -1899,7 +1899,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
>  		struct object_id rev;
>  
>  		if (repo_get_oid_mb(the_repository, opts->from_treeish, &rev))
> -			die(_("could not resolve %s"), opts->from_treeish);
> +			die(_("could not resolve '%s'"), opts->from_treeish);
>  
>  		setup_new_branch_info_and_source_tree(&new_branch_info,
>  						      opts, &rev,

← back to recent threads