On Wed, Oct 22, 2025 at 4:53 PM Collin Funk <[email protected]> wrote:
> Santiago Vila <[email protected]> writes:
>
> > since diffutils v3.12 the option "--to-file" no longer works as expected
> > if its argument is a directory.
> >
> > diff --to-file=directory file1 file2 file3
> >
> > should compare file1, file2, and file3 to directory/file1, directory/file2,
> > and directory/file3, respectively.
> > But it only compares file1 to directory/file1 and reports for the
> > remaining comparisons:
> >
> > diff: directory: No such file or directory
>
> Reminds me of bug 79407. I'll have a look at a fix and adding a test.
>
> Here is how it behaved in some older versions vs. current:
>
>     $ mkdir -p directory && touch file{1,2,3} directory/file{1,2,3}
>     $ diff-3.5 --to-file=directory file1 file2 file3
>     $ echo $?
>     0
>     $ diff-3.10 --to-file=directory file1 file2 file3
>     $ echo $?
>     0
>     $ diff-current --to-file=directory file1 file2 file3
>     diff-current: directory: No such file or directory
>     diff-current: directory: No such file or directory
>     2

Here is a test script (attached, also):

  $ cat diff-to_file-test.sh
  #!/bin/sh

  rm -rf -- Dref Da Db Dc  || exit
  mkdir Dref
  echo uno > Dref/f1
  echo dos > Dref/f2
  echo tres > Dref/f3

  # replicate Dref
  for D in Da Db Dc  ;do
    cp -rT -- Dref "$D"
    done

  # add differences
  echo mas >> Db/f1
  echo todo >> Dc/f2

  set -- Da 'identical' Db 'first file different' Dc 'second file different'

  while [ 2 -le $# ]  ;do
    echo "=== $1: $2"
    diff --to-file=Dref -- "$1"/f1 "$1"/f2 "$1"/f3
    echo "($?)"
    shift  ;shift
    done

  echo '=== DONE'

A run with the current version:

  $ diff --version  |head -n 2
  diff (GNU diffutils) 3.12
  Packaged by openSUSE
  $ ./diff-to_file-test.sh
  === Da: identical
  diff: Dref: No such file or directory
  diff: Dref: No such file or directory
  (2)
  === Db: first file different
  2d1
  < mas
  diff: Dref: No such file or directory
  diff: Dref: No such file or directory
  (2)
  === Dc: second file different
  diff: Dref: No such file or directory
  diff: Dref: No such file or directory
  (2)
  === DONE

An older version with the expected output:

  $ diff --version  |head -n 2
  diff (GNU diffutils) 3.6
  Packaged by openSUSE
  $ ./diff-to_file-test.sh
  === Da: identical
  (0)
  === Db: first file different
  2d1
  < mas
  (1)
  === Dc: second file different
  2d1
  < todo
  (1)
  === DONE

-- 
Robert Webb

Attachment: diff-to_file-test.sh
Description: application/shellscript

Reply via email to