127 Commits

Author SHA1 Message Date
Andreas Gruenbacher
fc5ddce20e Repair 'backup of unmodified file' test
tests/create-delete: Repair 'backup of unmodified file' test.
2012-09-28 18:39:33 +02:00
Andreas Gruenbacher
e8bfce6547 Improve the previous commit
* src/patch.c: Only print the "file is not empty after patch" message when
trying to delete the output file.  Say that we were trying to delete the file.
* tests/create-delete: Fix the expected messages.  Add test cases for the
--remove-empty-files and --posix options.
* NEWS: Better describe this change.
2012-09-26 01:33:22 +02:00
Andreas Gruenbacher
1d9ed51e9c Only expect files to become empty if the patch says so
Test cases based on patches from Dmitry V. Levin <ldv@altlinux.org>.
* src/patch.c (main): Only expect files to become empty if the patch says so.
* NEWS: Document this change.
* tests/create-delete: Add (more) empty vs. non-empty test cases.
2012-09-25 04:07:53 +02:00
Andreas Gruenbacher
3ccb16e10b Improve messages when in --dry-run mode
* src/patch.c (main): Say that we are checking a file and not that we are
patching it in --dry-run mode.  Don't say "saving rejects to file" when we
don't create reject files.
* tests/reject-format: Add rejects with --dry-run test case.
* tests/bad-filenames, tests/fifo, tests/mixed-patch-types: Update.
2012-09-22 20:10:53 +02:00
Andreas Gruenbacher
db1bd7f693 Improve handling of LF vs. CRLF line endings
* src/patch.c (check_line_endings): New function.
(main): When a hunk fails, report when the line endings differ between the
input file and the patch.
* src/pch.c (there_is_another_patch): When saying that we strip trailing CRs,
also say how to turn this off.
* tests/crlf-handling: Update changed messages.  Add test case that fails.
2012-09-22 20:02:48 +02:00
Andreas Gruenbacher
1d9d403394 Add a missing explanation in the tests/crlf-handling test case
* tests/crlf-handling: Add explanation.
2012-09-20 04:34:40 +02:00
Andreas Gruenbacher
293415dbcf Add --follow-symlinks option for backwards compatibility
* src/common.h (follow_symlinks): New variable.
* src/patch.c (longopts): Add new --follow-symlinks option.
(get_some_switches): Recognize the new option.
* src/util.c (stat_file): Follow symlinks if requested.
* patch.man: Document the new option.
* tests/symlinks: Add test case.
2012-09-19 03:16:07 +02:00
Andreas Gruenbacher
99f2638763 Fix file truncation when switching from git diff to non-git diff
* src/patch.c (main): Output queued output files only when switching from a git
diff to a non-git diff.  This can modify the input file, so make sure to
stat() it again.
* tests/concat-git-diff: Add test case growing a file with a git diff and then
with a non-git diff; without this fix; the result would be truncated.
2012-09-18 12:53:38 +02:00
Andreas Gruenbacher
4c7c0976ac Improve error message when patching a file of different type
* src/inp.c (get_input_file): Improve error message when patching a file of
different type.
* tests/symlinks: Update test case.
2012-09-18 00:48:01 +02:00
Andreas Gruenbacher
95f6823325 Minor test case updates
* tests/dash-o-append: Minor update (still expected to fail).
* tests/symlinks: Minor update.
2012-09-18 00:47:30 +02:00
Andreas Gruenbacher
20c9d7d5ab Allow to use potentially dangerous filenames from the root directory
* src/pch.c (cwd_is_root): New function to check if we are in the root
directory of a filename.
(name_is_valid): Allow to use potentially dangerous filenames when the current
working directory is the root directory: from there, those names are not
any more dangerous than other names.
* tests/bad-filenames: New test case.
2012-09-17 15:48:06 +02:00
Andreas Gruenbacher
281537bcd9 In a git-style diff, make sure not to unlink the original by accident
* src/patch.c (main): Fail if a file is not empty as expected.
(output_files): In a git-style diff, make sure not to unlink the original when
making a backup of an unmodified file.
* tests/create-delete: Fix failed-file-deletion test and add
successful-file-deletion test.
2012-09-13 16:32:53 +02:00
Andreas Gruenbacher
66aeedee12 Support double-quoted filenames in all context diff formats
* src/util.c (fetchname): Always recognize double-quoted filenames.
* src/util.h (fetchname): Update prototype.
* src/pch.c (intuit_diff_type): Update calls to fetchname().
* tests/quoted-filenames: Change to a normal unified diff.
* NEWS: Update.
2012-08-11 11:09:11 +02:00
Andreas Gruenbacher
a18960d31e Detect concatenated git-style patches by tracking what's in the output queue
* src/patch.c (main): Instead of looking at the SHA hashes to detect
concatenated git-style patches, detect when a file to write to is already in
the output queue.
* tests/concat-git-diff: Add create/delete tests.
2012-08-08 13:39:08 +02:00
Dmitry V. Levin
3980c923dc Add another git-style diff concatenation regression test
* tests/concat-git-diff: Add test case here.
2012-08-08 13:02:31 +02:00
Andreas Gruenbacher
a3f2ca32c3 maint: ignore more build artifacts 2012-08-08 01:41:42 +02:00
Andreas Gruenbacher
1e6c0d07ab In git-style diffs, create new files immediatetly and only remember files to modify
* src/patch.c (output_file): Create new files immediately.  Document why
things are implemented that way.
* tests/concat-git-diff: Fix glitch in test case.
2012-08-02 20:38:31 +02:00
Andreas Gruenbacher
120927804d Add file create test case which still needs to be fixed
* tests/concat-git-diff: Add file create test case.
2012-08-01 15:10:22 +02:00
Andreas Gruenbacher
6be1a126bd Try to recognize concatenated git diffs and handle them appropriately
* src/patch.c (main): Remember the "before" SHA1 hashes of git-style patches;
the same patch will always use the same "before" SHA1 for a specific file.
Try to recognize concatenated patches based on that.
* tests/concat-git-diff: New test case.
* tests/Makefile.am (TESTS): Add new test case.
2012-08-01 04:28:07 +02:00
Andreas Gruenbacher
6e21796422 Add missing "diff --git" index lines
* tests/copy-rename, tests/criss-cross, tests/file-modes,
tests/mixed-patch-types, tests/quoted-filenames: Add missing index lines in the
"dif --git" test cases: We will use some of them for consistency checks soon.
2012-07-31 21:58:24 +02:00
Andreas Gruenbacher
90d4e1f3d5 Fix segfault in output_file_later()
Bug reported by Dmitry V. Levin <ldv@altlinux.org>.
* src/patch.c (output_file_later): Fix case where the output file is identical
with the input file (and to == NULL).
2012-04-24 12:37:26 +02:00
Andreas Gruenbacher
9a26fde226 Only warn when trying to modify read-only files
Failing when trying to patch read-only files causes various users of patch to
break.  Instead, warn by default and introduce a command line option for
choosing a different behavior.
* patch.man: Describe the new behavior and command-line option.
* src/patch.c (read_only_behavior): New variable.
(main): Implement the new behavior.
(longopts): Add the new --read-only option.
(option_help): Describe the new behavior.
(get_some_switches): Recognize the new --read-only option.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
b9a1ff0cfa Fix "delete file which does not exist" test case
* tests/create-delete: Remove left-over file f.orig before the test.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
c43eeb22a4 For git-style patch files, do not output files immediately
In git-style patch files, all patches refer to the initial state of the input
files; files cannot be modified more than once.  Implement these semantics by
creating all output files once all patches in the patch file have been
processed.
* src/patch.c (init_files_to_output, output_files): Add prototypes.
(main): Remember which type of patch file we are processing.  Initialize the
output files list.  Output files of git-style patches once all patches have
been read, or when from git-style to normal patches.
(file_to_output): New struct.
(files_to_output): List of the files to output.
(output_file, output_file_now, output_file_later): Either queue a file for
deletion, remember to output a file later (git-style), or output the file
immediately (normal).
(dispose_file_to_output, init_files_to_output, output_files,
 forget_output_files): New functions.
(gl_list_clear): Should be provided by gnulib but isn't.
(cleanup): Clean up any left-over temporary output files as well.
* tests/Makefile-am (XFAIL_TESTS): Remove criss-cross; this test case works now.
* tests/mixed-patch-types: Patch files that change from normal to git-style, or
from git-style to normal.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
5081f42226 Remove invalid symlink test case
* tests/symlinks: Remove test case which deletes and then recreates a symlink:
all patches in a git-style input file must refer to the "before" state; the
test case is invalid.
2012-04-17 16:48:19 +02:00
Jim Meyering
d0745f417c maint: enable the sc_space_tab syntax-check rule
* cfg.mk (local-checks-to-skip): Remove sc_space_tab,
thus enabling this syntax-check rule.
* tests/quoted-filenames: Use TAB-space, not space-TAB.
2012-01-01 11:26:31 +01:00
Jim Meyering
2d38b11799 maint: update all copyright year number ranges
Run "make update-copyright".
2012-01-01 10:26:02 +01:00
Andreas Gruenbacher
5ca55b8414 Timestamp not set when creating files with --set-time or --set-utc
* src/util.h (enum file_attributes): Add FA_XATTRS flag for extended
attributes.
* src/patch.c (main): Use set_file_attributes() even when the infile doesn't
exist: it may still set the file time (FA_TIMES).  Omit all other FA_ flags if
infile doesn't exist.  Otherwise, add FA_XATTRS as well.
* src/util.c (set_file_attributes): Only copy extended attributes if FA_XATTRS
is set.  Avoid using st where it may be undefined.
* tests/preserve-mode-and-timestamp: Add file create test.
2011-12-09 00:53:38 +01:00
Stefano Lattarini
17086c5cf2 tests: specify test runner in LOG_COMPILER, not in TEST_ENVIRONMENT
* tests/Makefile.am (TESTS_ENVIRONMENT): Don't use $(SHELL) here
to ensure the test scripts are run through it; instead, ...
(LOG_COMPILER): ... use it here.
2011-10-12 00:34:19 +02:00
Jim Meyering
4e595c3b6d give a diagnostic rather than a failed assertion for a mangled patch
* src/pch.c (another_hunk): Rather than asserting(C), issue the
"replacement text or line numbers mangled ..." diagnostic when !C.
* tests/mangled-numbers-abort: New test for the above.
* tests/Makefile.am (TESTS): Add it.
* NEWS: Mention it.
Reported by Gabriel Vlasiu via Tim Waugh.
See also http://bugzilla.redhat.com/738959
2011-10-11 03:31:57 +02:00
Jim Meyering
db2fb7cdba maint: update copyright date year ranges to include 2011
* bootstrap.conf (gnulib_modules): Add update-copyright.
Run "make update-copyright".
2011-03-27 09:16:46 +02:00
Jim Meyering
2876ed918f maint: avoid non-portable use of test -a
With these changes, "make sc_prohibit_test_minus_ao" almost passes.
Uses of "test -o" remain.
Note: unchecked uses of test -ot/-nt also remain.
* tests/empty-files: Use "test C1 && test C2", not "test C1 -a C2"
* tests/merge: Likewise.
* tests/symlinks: Likewise.
* tests/test-lib.sh: Likewise.
2011-03-26 14:20:28 +01:00
Jim Meyering
02e3376350 maint: allow the sc_prohibit_empty_lines_at_EOF test to pass
* tests/test-lib.sh: Remove empty line at end of file.
2011-03-26 14:20:28 +01:00
Jim Meyering
07d4792620 maint: remove trailing blanks
* bootstrap.conf: Remove trailing blanks.
* tests/reject-format: Define a dummy, empty variable, and use it in
here-doc to protect required trailing blanks from accidental removal.
* tests/no-newline-triggers-assert: Likewise.
* tests/preserve-c-function-names: Likewise.
* tests/create-delete: Likewise.
* tests/global-reject-files: Complete a sentence that ended in a space.
2011-03-26 14:20:28 +01:00
Jim Meyering
e0f707523c don't warn twice about the same invalid file name
* src/pch.c (name_is_valid): Don't warn about the same name twice.
* tests/bad-filenames (emit_patch): Exercise the new code.
2011-02-17 10:00:57 +01:00
Andreas Gruenbacher
f663762bf0 Ignore dangerous filenames instead of failing immediately
* src/pch.c (name_is_valid): New function.
(intuit_diff_type, best_name): Use name_is_valid() here.
(strip_leading_slashes): Remove name validation tests from here.
* tests/bad-filenames: Add more tests for covering more of the
file name guessing corner cases in intuit_diff_type(), update the
existing tests.
* NEWS: Update.
2011-02-16 12:01:19 +01:00
Ozan Çağlayan
3fc5b24073 Create directory test case
* tests/create-delete: New test case creating a file in a new
sub-directory (bug fixed on 2010-12-04).
2011-02-04 00:10:28 +01:00
Andreas Gruenbacher
3c776b0844 Also check if the input file is seekable if a filename is given (-i)
* src/pch.c (open_patch_file): Also check if the input file is
seekable if a filename is given (-i).
* tests/pipe: New file.  Test this.
* tests/Makefile.am (TESTS): Add it.
2011-02-03 23:22:56 +01:00
Jim Meyering
685a78b605 Do not let a malicious patch create files above current directory
This addresses CVE-2010-4651, reported by Jakub Wilk.
https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2010-4651
* src/util.c (strip_leading_slashes): Reject absolute file names
and file names containing a component of "..".
* tests/bad-filenames: New file.  Test for this.
* tests/Makefile.am (TESTS): Add it.
Improvements by Andreas Gruenbacher.
2011-02-03 22:00:50 +01:00
Andreas Gruenbacher
3e234c40d2 Only recognize quited filename in the "diff --git" format
* src/util.c: Add a maybe_quoted parameter to fetchname.
* src/pch.c: Only recognize quited filename in the "diff --git"
format, at least for now.
* tests/quoted-filenames: Update accordingly.
* NEWS: Update accordingly.
2010-10-05 19:21:35 +02:00
Andreas Gruenbacher
86e12910c6 Add copy-after-modify test case
* tests/criss-cross: Add copy-after-modify test case.
2010-09-17 13:35:58 +02:00
Andreas Gruenbacher
7e6d1e6718 Document that "diff --git" criss-cross renames don't work
* NEWS: Document that "diff --git" criss-cross renames are broken
still.
* tests/criss-cross: Test case currently expected to fail.
2010-09-17 13:16:08 +02:00
Andreas Gruenbacher
19aecf8108 Fix the "patching file" message for renames and copies
* src/patch.c (main): Generate the "patching file" message here.  When
the input and output file name is not he same, include both names in
the message.
* src/inp.c (scan_input): Previously the "patching file" message was
generated here.
* tests/unmodified-files, tests/copy-rename: Update.
2010-09-17 12:19:43 +02:00
Andreas Gruenbacher
423d17d562 test suite: Another Solaris portability fix
* tests/corrupt-reject-files, tests/crlf-handling: On Solaris, cat's
-e option is only effective if -v is specified as well.
2010-05-06 18:48:02 +02:00
Andreas Gruenbacher
d94b00785d test suite: Ignore error messages during cleanup
* tests/test-lib.sh: Ignore error messages when cleaning up after a
test has finished.
2010-05-06 18:44:24 +02:00
Andreas Gruenbacher
7e9296614a test library: Only use GNU diff when available
* tests/test-lib.sh: Only use GNU diff when available.
* tests/dash-o-append: Fix the expected result.
2010-05-05 13:09:18 +02:00
Andreas Gruenbacher
99d75edf46 More test suite fixes
* tests/create-delete: Do not use 'diff' here.
* tests/merge: Require GNU diff.
2010-05-05 12:18:41 +02:00
Andreas Gruenbacher
ad76f67285 tests/read-only-files: Replace the superuser test
* tests/read-only-files: Remove the superuser test, and instead try
out if a read-only file can be written to.
2010-05-04 22:12:00 +02:00
Andreas Gruenbacher
9dbdc0e748 Create temporary test directories in builddir
* tests/test-lib.sh: Create temporary directories in builddir; this
removes the need to do it safely: some systems do not have mktemp -d.
2010-05-04 21:46:12 +02:00
Andreas Gruenbacher
80cfee88e6 Remove $(TEST_SHELL) and use $(SHELL) instead.
* configure.ac, tests/Makefile: Remove $(TEST_SHELL) and use $(SHELL)
instead.
2010-05-04 18:58:13 +02:00