Skip to contentSkip to conversation

subtle bug in git-am

DISCUSSION Andy Shevchenko 3 participants 4 messages Apr 7, 2020 – Apr 30, 2020

lore
Share & tools
lore
#0 lore raw

Hi!

What I would like to do is to apply patch from one repository to another with same files but *different directory structure*.

When I try to change directory in the target repo to the folder of files, I run git-am -p5 my_cool_patch.patch.

Instead of the expected result (files and their contents is the same!) I got fileXXX is not in index.

So, I think this is a bug, because -p<n> use in git-am makes little to no sense without above feature.

Perhaps I didn't understand something.
Please, advise.

$ git version
git version 2.25.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#1 lore raw
Quoted 5 lines · Andy Shevchenko

Hi!

What I would like to do is to apply patch from one repository to another with same files but *different directory structure*.

Quoted 8 lines

When I try to change directory in the target repo to the folder of files, I run git-am -p5 my_cool_patch.patch.

Instead of the expected result (files and their contents is the same!) I got fileXXX is not in index.

So, I think this is a bug, because -p<n> use in git-am makes little to no sense without above feature.

So if I understand correctly, you're expecting git am to apply relative to the current directory in the repository. I have also expected that behavior in the past, and found it surprising when it did not.

What git am does is apply relative to the root of the repository. If you'd instead like to apply to a specific subdirectory of the repository, you can use the --directory option to specify to which directory your patch should apply.

This is the behavior of git apply, which underpins git am. However, outside of a repository, it _does_ apply relative to the current directory, since there's no repository root to consider. I, at least, found this confusing, but that's how it works.

Signature · 2 lines
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
#2 lore raw
Quoted 25 lines · brian m. carlson
Quoted 5 lines · Andy Shevchenko

Hi!

What I would like to do is to apply patch from one repository to another with same files but *different directory structure*.

Quoted 8 lines

When I try to change directory in the target repo to the folder of files, I run git-am -p5 my_cool_patch.patch.

Instead of the expected result (files and their contents is the same!) I got fileXXX is not in index.

So, I think this is a bug, because -p<n> use in git-am makes little to no sense without above feature.

So if I understand correctly, you're expecting git am to apply relative to the current directory in the repository. I have also expected that behavior in the past, and found it surprising when it did not.

What git am does is apply relative to the root of the repository. If you'd instead like to apply to a specific subdirectory of the repository, you can use the --directory option to specify to which directory your patch should apply.

Quoted 4 lines

This is the behavior of git apply, which underpins git am. However, outside of a repository, it _does_ apply relative to the current directory, since there's no repository root to consider. I, at least, found this confusing, but that's how it works.

Thank you for the prompt reply with useful information. I will try it whenever I will need similar flow again.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 25 lines · Andy Shevchenko
Quoted 23 lines · brian m. carlson
Quoted 11 lines · Andy Shevchenko

What I would like to do is to apply patch from one repository to another with same files but *different directory structure*.

When I try to change directory in the target repo to the folder of files, I run git-am -p5 my_cool_patch.patch.

Instead of the expected result (files and their contents is the same!) I got fileXXX is not in index.

So, I think this is a bug, because -p<n> use in git-am makes little to no sense without above feature.

So if I understand correctly, you're expecting git am to apply relative to the current directory in the repository. I have also expected that behavior in the past, and found it surprising when it did not.

What git am does is apply relative to the root of the repository. If you'd instead like to apply to a specific subdirectory of the repository, you can use the --directory option to specify to which directory your patch should apply.

Quoted 7 lines
Quoted 4 lines

This is the behavior of git apply, which underpins git am. However, outside of a repository, it _does_ apply relative to the current directory, since there's no repository root to consider. I, at least, found this confusing, but that's how it works.

Thank you for the prompt reply with useful information. I will try it whenever I will need similar flow again.

Today I have needed something similar and I checked proposed w/a and it works! Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko