Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue on FreeBSD #159

Closed
RalfEisler opened this issue Sep 27, 2017 · 9 comments
Closed

Issue on FreeBSD #159

RalfEisler opened this issue Sep 27, 2017 · 9 comments

Comments

@RalfEisler
Copy link

--no-backup-if-mismatch
Do not back up a file if the patch does not match the file exactly and if backups are not otherwise requested. This is the default if patch is conforming to POSIX.

composer update -vvv
Running 1.5.2 (2017-09-11 16:59:25) with PHP 7.1.9 on FreeBSD / 10.3-RELEASE-p20

Executing command (CWD): patch '-p4' --no-backup-if-mismatch -d 'docroot/core' < '/tmp//59ca7004e02cf.patch'
patch: unrecognized option `--no-backup-if-mismatch'
usage: patch [-bCcEeflNnRstuv] [-B backup-prefix] [-D symbol] [-d directory]
             [-F max-fuzz] [-i patchfile] [-o out-file] [-p strip-count]
             [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]
             [--posix] [origfile [patchfile]]
       patch <patchfile

   Could not apply patch! Skipping. The error was: Cannot apply patch 

@cweagans
Copy link
Owner

cweagans commented Oct 2, 2017

I'm not sure what you're asking for here.

@RalfEisler
Copy link
Author

--no-backup-if-mismatch results in an error when patching on FreeBSD / 10.3-RELEASE-p20

@gambry
Copy link

gambry commented Nov 2, 2017

Also Busybox patch command (i.e. the one in any docker container using alpine, including the official composer image) doesn't like --no-backup-if-mismatch nor -d:

     BusyBox v1.24.2 (2017-01-18 14:13:46 GMT) multi-call binary.
     Usage: patch [OPTIONS] [ORIGFILE [PATCHFILE]]

     -p,--strip N            Strip N leading components from file names
     -i,--input DIFF         Read DIFF instead of stdin
     -R,--reverse            Reverse patch
     -N,--forward            Ignore already applied patches
     -E,--remove-empty-files Remove output files if they become empty

I suggest we add another if (!$patched) {} block with something like:

foreach ($patch_levels as $patch_level) {
  if ($patched = $this->executeCommand("cd %s && patch %s < %s", $install_path, $patch_level, $filename)) {
    break;
  }
}

@jtkoerting
Copy link

Can confirm the problem on FreeBSD 10.0 - 10.4 too. The reason is, that FreeBSD is not using the gnu patch by default.
As a workaround until the suggested change is applied, your can just install gpatch:

pkg install patch
ln -s gpatch /usr/local/bin/patch

and create a symlink like above. If you have a common $PATH, than gnu patch in /usr/local/bin/patch is preferred over the original under /usr/bin

Dunno, if the git patch fails only on FreeBSD, but here is the message (which seems to be the reason going to use patch at all):

cd 'docroot/modules/contrib/ctools' && git --git-dir=. apply --check '-p4' '/tmp//5a05e96e8b3a9.patch'
fatal: bad config line 1 in file config

patch '-p1' --no-backup-if-mismatch -d 'docroot/modules/contrib/ctools' < '/tmp//5a05e96e8b3a9.patch'
patching file modules/ctools_views/src/Plugin/Display/Block.php

There is a valid ~/.gitconfig that seems to be unused. Maybe you want to check your git call/files?

@Techwolf12
Copy link

Also see #182 and the fix for this: #184

@gambry
Copy link

gambry commented Feb 24, 2018

In the meanwhile to fix the issue mentioned above with docker composer official image I've create a POC image gambry/composer.
I'm going to test it a bit and if fixes the problem for running composer/patches through docker composer I will create a proper reliable docker repository, with test coverage.

@joris-vercammen-cali
Copy link

The problem is that --no-backup-if-mismatch also doesn't exist on alpine-linux. Which is what the official composer docker-images are built on. (https://hub.docker.com/_/composer/)

So to allow us to use those docker containers, we should remove that flag. This would be a behavior change, so not sure how to handle this with regards to BC-compatibility.

We also can't create a patch for composer-patches because:

  1. That would be a mindfuck
  2. We can't apply the patch ;)

The only fix I can think of, is to remove the flag and implement that behavior in php. I'm not sure if this is a good idea and if we should even try to do this.

@Techwolf12
Copy link

@joris-vercammen-cali See pull request #184 for a potential fix. It uses the posix flag which is available in alpine linux.

@cweagans
Copy link
Owner

cweagans commented Feb 7, 2023

main now has explicit support for BSD Patch, including not using the --no-backup-if-mismatch flag.

@cweagans cweagans closed this as completed Feb 7, 2023
cekovski added a commit to nobozolab/composer-patches that referenced this issue Sep 8, 2023
Fix issue "patch: unrecognized option `--no-backup-if-mismatch'"
See: cweagans#159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants