Subject: Re: [bug-diffutils] bug#79407: to-file option not working any more?

From: Robert Webb <[email-masked]>
Date: Mon, 8 Sep 2025 21:06:11 -0700

On Mon, Sep 8, 2025 at 6:12 AM Mandar Mitra <[email-masked]> wrote:
>
> When I specify a directory with the --to-file option, and ask diff to compare multiple files with the corresponding files under the to-file directory, only the first file is diffed; a "No such file or directory" message is displayed for everything else.
>
> [...]
> I'm reasonably sure this used to work earlier as I expected, but a quick search did not find any related discussions / bug reports.
> Could someone kindly confirm whether this is a bug or incorrect understanding on my part?

Mandar, I can confirm that the --to-file option as a directory results
in only the first command-line file
being diffed, with errors for the others.

This script (also attached as 'runtest02.sh') shows it whether the
first file is identical (b) or different (c):

  DIFFOPTS='-s'
  diff --version

  ecmd() { printf '\n=== %s\n' "$*"  ;"$@" ;}

  setup() {
  test ! -d t  || rm -r t  && mkdir t  || exit
  # Create 3 directories of 3 one-line files
  cd t  && mkdir a b c  || exit
  split --numeric-suffixes=1 -a 1 -l 1 --verbose -- - a/  <<'END'
  x
  xx
  xxx
  END
  split --numeric-suffixes=1 -a 1 -l 1 --verbose -- - b/  <<'END'
  x
  !!
  xxx
  END
  split --numeric-suffixes=1 -a 1 -l 1 --verbose -- - c/  <<'END'
  !
  xx
  !!!
  END
  }

  setup
  ecmd diff ${DIFFOPTS} --to-file b -- a/3 a/2 a/1
  ecmd diff ${DIFFOPTS} --to-file c -- a/3 a/2 a/1

And I just found out that an older version of diff handles this without errors.
First the old one:

  $ runtest02.sh -s
  diff (GNU diffutils) 3.6
  Packaged by openSUSE
  Copyright (C) 2017 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.

  Written by Paul Eggert, Mike Haertel, David Hayes,
  Richard Stallman, and Len Tower.
  creating file 'a/1'
  creating file 'a/2'
  creating file 'a/3'
  creating file 'b/1'
  creating file 'b/2'
  creating file 'b/3'
  creating file 'c/1'
  creating file 'c/2'
  creating file 'c/3'

  === diff -s --to-file b -- a/3 a/2 a/1
  Files a/3 and b/3 are identical
  1c1
  < xx
  ---
  > !!
  Files a/1 and b/1 are identical

  === diff -s --to-file c -- a/3 a/2 a/1
  1c1
  < xxx
  ---
  > !!!
  Files a/2 and c/2 are identical
  1c1
  < x
  ---
  > !

And the new one:

  $ runtest02.sh -s
  diff (GNU diffutils) 3.12
  Packaged by openSUSE
  Copyright (C) 2025 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>.
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.

  Written by Paul Eggert, Mike Haertel, David Hayes,
  Richard Stallman, and Len Tower.
  creating file 'a/1'
  creating file 'a/2'
  creating file 'a/3'
  creating file 'b/1'
  creating file 'b/2'
  creating file 'b/3'
  creating file 'c/1'
  creating file 'c/2'
  creating file 'c/3'

  === diff -s --to-file b -- a/3 a/2 a/1
  Files a/3 and b/3 are identical
  diff: b: No such file or directory
  diff: b: No such file or directory

  === diff -s --to-file c -- a/3 a/2 a/1
  1c1
  < xxx
  ---
  > !!!
  diff: c: No such file or directory
  diff: c: No such file or directory

-- 
Robert Webb