0

Having a .diff patch file, I'm trying to take actions in a shell script depending on if files listed in .diff file are: 1) already patched, 2) not patched, 3) not patchable.

I found no way on GNU Patch to show this information in a non-interactive basis.

Also would be useful knowing which files are to be patched without patching them. This seem to be easier filtering the .diff file but would be great if GNU Patch had these features.

Some suggestion on this?

Emilio Lazo
  • 119
  • 3
  • Have you tried `--dry-run`? – Michael Hampton Apr 03 '16 at 06:19
  • Yes @MichaelHampton. Without `-t` and `-f` it may be interactive (when patch is already applied). The closest solution would be executing `--dry-run -fNs` and `--dry-run -fRs`. If both exits with exit code 1 we have an error (not patchable); if `-fNs` exits with 0 means that files are to be patched, and if `-fRs` exits with code 0 means that files are already patched. – Emilio Lazo Apr 03 '16 at 06:47

1 Answers1

1

I've found a solution.

To show the list of files to be processed: lsdiff from patchutils.

To determine the patch status of the tree I wrote this sh function:

checkpatch(){
 local normal reverso file

 file="$1"

 patch -p1 --dry-run -fNs < "$file" &>/dev/null && normal=0 || normal=1
 patch -p1 --dry-run -fRs < "$file" &>/dev/null && reverso=0 || reverso=1

 if [ "$normal" == "1" ] && [ "$reverso" == "1" ]; then
    echo Error ; return 2
 else
    if [ "$normal" == "0" ]; then
       echo Not patched ; return 1
    else
       echo Patched ; return 0
    fi
 fi
}

Use checkpatch followed with a .diff file and it will say whether the tree is patched or not.

Emilio Lazo
  • 119
  • 3