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
I am trying to use git apply --unsafe-paths as a "better GNU patch" (aka as replacement for the GNU patch executable).
However, this is not really working out as expected and stated by its documentation.
What did you do before the bug happened? (Steps to reproduce your issue)
Follow these steps to reproduce the issue:
git clone a Git repository which contains a Git submodule, e.g., the Git repository itself:
Change into the cloned source directory and initialize the submodule(s), e.g., the single submodule sha1collisiondetection of the Git repository:
cd source && git submodule update --init
Change into the directory of that Git submodule and create a patch for a file in it.
(Afterwards change into the root source directory again.)
cd sha1collisiondetection
echo "Some additional text to append to the readme file." >> README.md
git diff -u README.md > README.md.patch
git checkout README.md
cd ..
Now we have 4 different cases to consider:
Case 1: Copy the directory of this Git submodule into another directory which itself is not located in or beneath a directory under Git control.
cp -r sha1collisiondetection ../case-1
Case 2: Same as for case 1, but additionally remove the .git file in that copied directory.
Case 3 failed in step 5 with the following message:
fatal: cannot chdir to '../../../sha1collisiondetection': No such file or directory
Case 4 failed in step 5 with the following message:
Skipped patch 'README.md'.
What's different between what you expected and what actually happened?
I would have expected that option --unsafe-paths allows me to patch any file using git apply no matter where the directory is located and whether there is a .git file or directory in any of its parent directories or not.
That would have allowed me to use git apply --unsafe-paths as an alternative to GNU patch (which might not be available on all platforms) as written in git apply's man page.
Anything else you want to add:
If this is behavior as designed, the documentation then really needs clarification. Additionally, git apply should then provide another option --simulate-patch (or similar called) which really works as a GNU patch replacement in all situations (and does not get distracted by the existence of a file or directory with called .git).
This described problem with git apply --unsafe-paths occurs on Windows as well as on Linux (and probably any other platform for which Git is available).
[System Info]
git version:
git version 2.38.1.windows.1
cpu: x86_64
built from commit: b85c8f6
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Windows 10.0 22000
compiler info: gnuc: 12.2
libc info: no libc information available
$SHELL (typically, interactive shell): C:\Program Files\Git\usr\bin\bash.exe
[Enabled Hooks]
not run from a git repository - no hooks to show
The text was updated successfully, but these errors were encountered:
@Bagira80 Thank you for writing up a bug report. However, this is not the place the Git projects expects bug reports: please send it to the Git mailing list. See https://git-scm.com/community for more details.
Thank you, @dscho, but sending this bug report directly via the Git mailing list is what I already tried almost a year ago. Nobody seemed to have noticed.
So, I thought, maybe reporting it here might bring it to the attention of Git developers that feel responsible for git apply. I assumed the message might automatically be put on the Git mailing list (as I understand is the case with pull requests)?
Introduction
I am trying to use
git apply --unsafe-paths
as a "better GNU patch" (aka as replacement for the GNUpatch
executable).However, this is not really working out as expected and stated by its documentation.
What did you do before the bug happened? (Steps to reproduce your issue)
Follow these steps to reproduce the issue:
git clone
a Git repository which contains a Git submodule, e.g., the Git repository itself:Change into the cloned source directory and initialize the submodule(s), e.g., the single submodule
sha1collisiondetection
of the Git repository:Change into the directory of that Git submodule and create a patch for a file in it.
(Afterwards change into the root source directory again.)
Now we have 4 different cases to consider:
Case 1: Copy the directory of this Git submodule into another directory which itself is not located in or beneath a directory under Git control.
Case 2: Same as for case 1, but additionally remove the
.git
file in that copied directory.Case 3: Rename the directory of this submodule but do not inform Git about it.
Case 4: Same as for case 3, but additionally remove the
.git
file in that moved directory.For each directory created under the sub-steps of 4 change into it and run
git apply
with--unsafe-paths
option:What did you expect to happen? (Expected behavior)
I expected all four different scenarios to succeed and
git apply
to successfully patchREADME.md
in step 5 similar to GNUpatch
executable.What happened instead? (Actual behavior)
Case 1 failed in step 5 with the following message:
Case 2 succeeded in step 5 with the following message:
Case 3 failed in step 5 with the following message:
Case 4 failed in step 5 with the following message:
What's different between what you expected and what actually happened?
I would have expected that option
--unsafe-paths
allows me to patch any file usinggit apply
no matter where the directory is located and whether there is a.git
file or directory in any of its parent directories or not.That would have allowed me to use
git apply --unsafe-paths
as an alternative to GNUpatch
(which might not be available on all platforms) as written ingit apply
's man page.Anything else you want to add:
If this is behavior as designed, the documentation then really needs clarification. Additionally,
git apply
should then provide another option--simulate-patch
(or similar called) which really works as a GNUpatch
replacement in all situations (and does not get distracted by the existence of a file or directory with called.git
).This described problem with
git apply --unsafe-paths
occurs on Windows as well as on Linux (and probably any other platform for which Git is available).[System Info]
git version:
git version 2.38.1.windows.1
cpu: x86_64
built from commit: b85c8f6
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Windows 10.0 22000
compiler info: gnuc: 12.2
libc info: no libc information available
$SHELL (typically, interactive shell): C:\Program Files\Git\usr\bin\bash.exe
[Enabled Hooks]
not run from a git repository - no hooks to show
The text was updated successfully, but these errors were encountered: