From dccdcb53bfd7e0888a4d6bb6a174005d95c48595 Mon Sep 17 00:00:00 2001
From: Lubomír Sedlář <lsedlar@redhat.com>
Date: Oct 02 2017 08:44:56 +0000
Subject: [PATCH 1/2] Remove unused variable


Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>

---

diff --git a/compose_utils/copy_compose.py b/compose_utils/copy_compose.py
index 29693c2..a60f675 100644
--- a/compose_utils/copy_compose.py
+++ b/compose_utils/copy_compose.py
@@ -28,12 +28,12 @@ def copy_compose(compose, dest, arches=None, variants=None, dry_run=False, rsync
             continue
 
         if not arches or (variant_arches & arches) == variant_arches:
-            paths.extend(_collect_variant(compose, variant, dest, arch=None))
+            paths.extend(_collect_variant(compose, variant, arch=None))
         else:
             for arch in variant_arches:
                 if arch not in arches:
                     continue
-                paths.extend(_collect_variant(compose, variant, dest, arch=arch))
+                paths.extend(_collect_variant(compose, variant, arch=arch))
 
     paths = _reduce(compose, paths)
     for parent, children in paths.iteritems():
@@ -58,7 +58,7 @@ def _run_rsync(sources, destination, dry_run=False, opts=[]):
         shortcuts.run(cmd, stdout=True)
 
 
-def _collect_variant(compose, variant, dest, arch=None):
+def _collect_variant(compose, variant, arch=None):
     """Find all paths in a variant that should be copied.
     If arch is not specified, that means all paths, otherwise only paths
     defined for the arch will be copied.

From 68399ac288994aa71be90b1bf15242844dde58e2 Mon Sep 17 00:00:00 2001
From: Lubomír Sedlář <lsedlar@redhat.com>
Date: Oct 02 2017 08:46:23 +0000
Subject: [PATCH 2/2] Fix copying when compose path ends with slash


Fixes: https://pagure.io/compose-utils/issue/60
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>

---

diff --git a/compose_utils/copy_compose.py b/compose_utils/copy_compose.py
index a60f675..89fba44 100644
--- a/compose_utils/copy_compose.py
+++ b/compose_utils/copy_compose.py
@@ -35,10 +35,11 @@ def copy_compose(compose, dest, arches=None, variants=None, dry_run=False, rsync
                     continue
                 paths.extend(_collect_variant(compose, variant, arch=arch))
 
+    compose_path = compose.compose_path.rstrip('/')
     paths = _reduce(compose, paths)
     for parent, children in paths.iteritems():
         sources = sorted([os.path.join(parent, child) for child in children])
-        destination = os.path.join(dest, parent.replace(compose.compose_path, '').lstrip('/'))
+        destination = os.path.join(dest, parent.replace(compose_path, '').lstrip('/'))
         _run_rsync(sources, destination, dry_run=dry_run, opts=rsync_opts)
 
     if not dry_run:
diff --git a/tests/helpers.py b/tests/helpers.py
index aa4f5d9..2c747b3 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -11,9 +11,10 @@ def get_compose_path(ident):
     return pth
 
 
-def get_compose(ident):
+def get_compose(ident, path=None):
     """Load a test compose and return the Compose instance."""
-    return productmd.compose.Compose(get_compose_path(ident))
+    path = path or get_compose_path(ident)
+    return productmd.compose.Compose(path)
 
 
 def get_fixture(filename):
diff --git a/tests/test_copy_compose.py b/tests/test_copy_compose.py
index d08bb23..e35611b 100644
--- a/tests/test_copy_compose.py
+++ b/tests/test_copy_compose.py
@@ -9,7 +9,7 @@ import shutil
 
 from compose_utils import copy_compose
 
-from .helpers import get_compose
+from .helpers import get_compose, get_compose_path
 
 
 class ChangelogTest(unittest.TestCase):
@@ -41,6 +41,18 @@ class ChangelogTest(unittest.TestCase):
         self.assertComposeId()
 
     @mock.patch('kobo.shortcuts.run')
+    def test_copy_full_variant_from_explicit_path(self, mock_run):
+        self.compose = get_compose(get_compose_path('DP-1.0-20160315.t.0') + '/compose/')
+        copy_compose(self.compose, self.dest, variants=['Server'], arches=[])
+        self.assertItemsEqual(
+            mock_run.mock_calls,
+            [mock.call(['rsync', '-avHh',
+                        os.path.join(self.compose.compose_path, 'Server'),
+                        self.dest],
+                       stdout=True)])
+        self.assertComposeId()
+
+    @mock.patch('kobo.shortcuts.run')
     def test_copy_to_missing_dir(self, mock_run):
         self.dest = os.path.join(self.dest, 'missing', 'directory') + '/'
         copy_compose(self.compose, self.dest, variants=[], arches=[])

