diff --git a/osc/core.py b/osc/core.py
index 316d9a7e..a02b1290 100644
--- a/osc/core.py
+++ b/osc/core.py
@@ -1340,8 +1340,9 @@ class Package:
deleted = []
def diff_add_delete(fname, add, revision):
diff = []
- diff.append(diff_hdr % f)
+ diff.append(diff_hdr % fname)
tmpfile = None
+ origname = fname
if add:
diff.append('--- %s\t(revision 0)\n' % fname)
rev = 'revision 0'
@@ -1357,8 +1358,15 @@ class Package:
try:
if revision is not None and not add:
(fd, tmpfile) = tempfile.mkstemp(prefix='osc_diff')
- get_source_file(self.apiurl, self.prjname, self.name, os.path.basename(f), tmpfile, revision)
+ get_source_file(self.apiurl, self.prjname, self.name, origname, tmpfile, revision)
fname = tmpfile
+ if binary_file(fname):
+ what = 'added'
+ if not add:
+ what = 'deleted'
+ diff = diff[:1]
+ diff.append('Binary file \'%s\' %s.\n' % (origname, what))
+ return diff
tmpl = '+%s'
ltmpl = '@@ -0,0 +1,%d @@\n'
if not add:
@@ -3357,7 +3365,7 @@ def get_source_file_diff(dir, filename, rev, oldfilename = None, olddir = None,
file1 = os.path.join(olddir, oldfilename) # old/stored original
file2 = os.path.join(dir, filename) # working copy
if binary_file(file1) or binary_file(file2):
- return ['Binary file %s has changed\n' % origfilename]
+ return ['Binary file \'%s\' has changed.\n' % origfilename]
f1 = f2 = None
try:
diff --git a/tests/difffile_fixtures/osctest/binary/.osc/_apiurl b/tests/difffile_fixtures/osctest/binary/.osc/_apiurl
new file mode 100644
index 00000000..0afeace7
--- /dev/null
+++ b/tests/difffile_fixtures/osctest/binary/.osc/_apiurl
@@ -0,0 +1 @@
+http://localhost
diff --git a/tests/difffile_fixtures/osctest/binary/.osc/_files b/tests/difffile_fixtures/osctest/binary/.osc/_files
new file mode 100644
index 00000000..2c82894c
--- /dev/null
+++ b/tests/difffile_fixtures/osctest/binary/.osc/_files
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/tests/difffile_fixtures/osctest/binary/.osc/_osclib_version b/tests/difffile_fixtures/osctest/binary/.osc/_osclib_version
new file mode 100644
index 00000000..d3827e75
--- /dev/null
+++ b/tests/difffile_fixtures/osctest/binary/.osc/_osclib_version
@@ -0,0 +1 @@
+1.0
diff --git a/tests/difffile_fixtures/osctest/binary/.osc/_package b/tests/difffile_fixtures/osctest/binary/.osc/_package
new file mode 100644
index 00000000..a9128c28
--- /dev/null
+++ b/tests/difffile_fixtures/osctest/binary/.osc/_package
@@ -0,0 +1 @@
+binary
diff --git a/tests/difffile_fixtures/osctest/binary/.osc/_project b/tests/difffile_fixtures/osctest/binary/.osc/_project
new file mode 100644
index 00000000..b83ffd3c
--- /dev/null
+++ b/tests/difffile_fixtures/osctest/binary/.osc/_project
@@ -0,0 +1 @@
+osctest
diff --git a/tests/difffile_fixtures/osctest/binary/.osc/_to_be_added b/tests/difffile_fixtures/osctest/binary/.osc/_to_be_added
new file mode 100644
index 00000000..075a1514
--- /dev/null
+++ b/tests/difffile_fixtures/osctest/binary/.osc/_to_be_added
@@ -0,0 +1 @@
+binary_added
diff --git a/tests/difffile_fixtures/osctest/binary/.osc/_to_be_deleted b/tests/difffile_fixtures/osctest/binary/.osc/_to_be_deleted
new file mode 100644
index 00000000..705639e2
--- /dev/null
+++ b/tests/difffile_fixtures/osctest/binary/.osc/_to_be_deleted
@@ -0,0 +1 @@
+binary_deleted
diff --git a/tests/difffile_fixtures/osctest/binary/.osc/binary b/tests/difffile_fixtures/osctest/binary/.osc/binary
new file mode 100644
index 00000000..727c3660
Binary files /dev/null and b/tests/difffile_fixtures/osctest/binary/.osc/binary differ
diff --git a/tests/difffile_fixtures/osctest/binary/.osc/binary_deleted b/tests/difffile_fixtures/osctest/binary/.osc/binary_deleted
new file mode 100644
index 00000000..17e35eca
Binary files /dev/null and b/tests/difffile_fixtures/osctest/binary/.osc/binary_deleted differ
diff --git a/tests/difffile_fixtures/osctest/binary/binary b/tests/difffile_fixtures/osctest/binary/binary
new file mode 100644
index 00000000..58689788
Binary files /dev/null and b/tests/difffile_fixtures/osctest/binary/binary differ
diff --git a/tests/difffile_fixtures/osctest/binary/binary_added b/tests/difffile_fixtures/osctest/binary/binary_added
new file mode 100644
index 00000000..188a9378
Binary files /dev/null and b/tests/difffile_fixtures/osctest/binary/binary_added differ
diff --git a/tests/difffile_fixtures/osctest/remote_localmodified/.osc/_files b/tests/difffile_fixtures/osctest/remote_localmodified/.osc/_files
index f0dac1f4..7c4480a2 100644
--- a/tests/difffile_fixtures/osctest/remote_localmodified/.osc/_files
+++ b/tests/difffile_fixtures/osctest/remote_localmodified/.osc/_files
@@ -2,4 +2,5 @@
-
\ No newline at end of file
+
+
diff --git a/tests/difffile_fixtures/osctest/remote_localmodified/.osc/binary b/tests/difffile_fixtures/osctest/remote_localmodified/.osc/binary
new file mode 100644
index 00000000..58689788
Binary files /dev/null and b/tests/difffile_fixtures/osctest/remote_localmodified/.osc/binary differ
diff --git a/tests/difffile_fixtures/osctest/remote_localmodified/binary b/tests/difffile_fixtures/osctest/remote_localmodified/binary
new file mode 100644
index 00000000..ff2abf91
Binary files /dev/null and b/tests/difffile_fixtures/osctest/remote_localmodified/binary differ
diff --git a/tests/difffile_fixtures/osctest/remote_simple/binary b/tests/difffile_fixtures/osctest/remote_simple/binary
new file mode 100644
index 00000000..58689788
Binary files /dev/null and b/tests/difffile_fixtures/osctest/remote_simple/binary differ
diff --git a/tests/difffile_fixtures/testDiffRemoteExistingLocalNotExisting_binary b/tests/difffile_fixtures/testDiffRemoteExistingLocalNotExisting_binary
new file mode 100644
index 00000000..188a9378
Binary files /dev/null and b/tests/difffile_fixtures/testDiffRemoteExistingLocalNotExisting_binary differ
diff --git a/tests/difffile_fixtures/testDiffRemoteExistingLocalNotExisting_files b/tests/difffile_fixtures/testDiffRemoteExistingLocalNotExisting_files
index bfdf9df3..5ac058dc 100644
--- a/tests/difffile_fixtures/testDiffRemoteExistingLocalNotExisting_files
+++ b/tests/difffile_fixtures/testDiffRemoteExistingLocalNotExisting_files
@@ -3,4 +3,5 @@
+
diff --git a/tests/difffile_fixtures/testDiffRemoteUnchangedLocalModified_binary b/tests/difffile_fixtures/testDiffRemoteUnchangedLocalModified_binary
new file mode 100644
index 00000000..58689788
Binary files /dev/null and b/tests/difffile_fixtures/testDiffRemoteUnchangedLocalModified_binary differ
diff --git a/tests/difffile_fixtures/testDiffRemoteUnchangedLocalModified_files b/tests/difffile_fixtures/testDiffRemoteUnchangedLocalModified_files
index 4aec6afd..054024f1 100644
--- a/tests/difffile_fixtures/testDiffRemoteUnchangedLocalModified_files
+++ b/tests/difffile_fixtures/testDiffRemoteUnchangedLocalModified_files
@@ -2,4 +2,5 @@
+
diff --git a/tests/test_difffiles.py b/tests/test_difffiles.py
index 1a4083d9..2719d9de 100644
--- a/tests/test_difffiles.py
+++ b/tests/test_difffiles.py
@@ -133,6 +133,37 @@ class TestDiffFiles(OscTestCase):
@@ -1,1 +0,0 @@
-some content
""" % (TestDiffFiles.diff_hdr % 'nochange', TestDiffFiles.diff_hdr % 'somefile')
+ self.__check_diff(p, exp, None)
+
+ def testDiffBinaryAdded(self):
+ """diff an added binary file"""
+ self._change_to_pkg('binary')
+ p = osc.core.Package('.')
+ p.todo = ['binary_added']
+ exp = """%s
+Binary file 'binary_added' added.
+""" % (TestDiffFiles.diff_hdr % 'binary_added')
+ self.__check_diff(p, exp, None)
+
+ def testDiffBinaryDeleted(self):
+ """diff a deleted binary file"""
+ self._change_to_pkg('binary')
+ p = osc.core.Package('.')
+ p.todo = ['binary_deleted']
+ exp = """%s
+Binary file 'binary_deleted' deleted.
+""" % (TestDiffFiles.diff_hdr % 'binary_deleted')
+ self.__check_diff(p, exp, None)
+
+ def testDiffBinaryModified(self):
+ """diff a modified binary file"""
+ self._change_to_pkg('binary')
+ p = osc.core.Package('.')
+ p.todo = ['binary']
+ exp = """%s
+Binary file 'binary' has changed.
+""" % (TestDiffFiles.diff_hdr % 'binary')
+ self.__check_diff(p, exp, None)
# diff with revision
@GET('http://localhost/source/osctest/remote_simple_noadd?rev=3', file='testDiffRemoteNoChange_files')
@@ -182,6 +213,7 @@ class TestDiffFiles(OscTestCase):
@GET('http://localhost/source/osctest/remote_simple_noadd?rev=3', file='testDiffRemoteExistingLocalNotExisting_files')
@GET('http://localhost/source/osctest/remote_simple_noadd/foobar?rev=3', file='testDiffRemoteExistingLocalNotExisting_foobar')
+ @GET('http://localhost/source/osctest/remote_simple_noadd/binary?rev=3', file='testDiffRemoteExistingLocalNotExisting_binary')
def testDiffRemoteExistingLocalNotExisting(self):
"""
a file doesn't exist in the local wc but exists
@@ -195,11 +227,14 @@ class TestDiffFiles(OscTestCase):
@@ -1,2 +0,0 @@
-foobar
-barfoo
-""" % (TestDiffFiles.diff_hdr % 'foobar')
+%s
+Binary file 'binary' deleted.
+""" % (TestDiffFiles.diff_hdr % 'foobar', TestDiffFiles.diff_hdr % 'binary')
self.__check_diff(p, exp, 3)
@GET('http://localhost/source/osctest/remote_localmodified?rev=3', file='testDiffRemoteUnchangedLocalModified_files')
@GET('http://localhost/source/osctest/remote_localmodified/nochange?rev=3', file='testDiffRemoteUnchangedLocalModified_nochange')
+ @GET('http://localhost/source/osctest/remote_localmodified/binary?rev=3', file='testDiffRemoteUnchangedLocalModified_binary')
def testDiffRemoteUnchangedLocalModified(self):
"""remote revision didn't change, local file is modified"""
self._change_to_pkg('remote_localmodified')
@@ -210,7 +245,9 @@ class TestDiffFiles(OscTestCase):
@@ -1,1 +1,2 @@
This file didn't change.
+oh it does
-""" % (TestDiffFiles.diff_hdr % 'nochange')
+%s
+Binary file 'binary' has changed.
+""" % (TestDiffFiles.diff_hdr % 'nochange', TestDiffFiles.diff_hdr % 'binary')
self.__check_diff(p, exp, 3)
@GET('http://localhost/source/osctest/remote_simple_noadd?rev=3', file='testDiffRemoteMissingLocalExisting_files')