Repository: conan-io/conan

Issue:
svn scm bug when using a tag
conan 1.14.3

We have a component that has a recipe called 'conanfile_policy.py' in a sub directory called 'policy'. See:
![sophosmanager_dir](https://user-images.githubusercontent.com/25768447/56582902-3cd97d00-65d0-11e9-9ec1-13f60fae006d.png)

As part of our test build process this component gets tagged at the component root level ie above the policy dir, after the recipe was changed so a build can be done from the tag. The SVN revision graph showing this is:
![sophosmanager_svn_tag](https://user-images.githubusercontent.com/25768447/56583021-81651880-65d0-11e9-881d-792a611bbf05.png)

As part of our build process, Jenkins checks out the policy subdir using the tag and exports the recipe, this is preparation for doing a `conan create` on our 'product' recipe to build our entire product.

The url gets deduced incorrectly by scm auto in this export, which means Jenkins can’t `conan create` from the recipe for this component breaking the build. The exported recipe looks like:
```
scm = {"revision": "126",
           "type": "svn",
           "url": "svn+ssh://svnserver/svncmake/sophosmanager/tags/CONAN_REL_3.0.0-2/policy@125"}
```
The `conan create` fails because the tag does not exist at rev 125, only 126.

I think the issue might be how scm auto deduces the svn revision to create the url, it appears to use Last Changed Rev rather than the Revision attribute from the svn info. With a subdir under the tag, the Last Changed Rev doesn’t include the tag, as the tag didn’t occur in the subdir, but at the level above it.



Discussion:

Resolving patch:
diff --git a/conans/client/tools/scm.py b/conans/client/tools/scm.py
--- a/conans/client/tools/scm.py
+++ b/conans/client/tools/scm.py
@@ -310,7 +310,7 @@ def get_remote_url(self, remove_credentials=False):
     def get_qualified_remote_url(self, remove_credentials=False):
         # Return url with peg revision
         url = self.get_remote_url(remove_credentials=remove_credentials)
-        revision = self.get_last_changed_revision()
+        revision = self.get_revision()
         return "{url}@{revision}".format(url=url, revision=revision)
 
     def is_local_repository(self):


Test patch:
diff --git a/conans/test/functional/scm/issues/__init__.py b/conans/test/functional/scm/issues/__init__.py
new file mode 100644
diff --git a/conans/test/functional/scm/issues/test_svn_tag.py b/conans/test/functional/scm/issues/test_svn_tag.py
new file mode 100644
--- /dev/null
+++ b/conans/test/functional/scm/issues/test_svn_tag.py
@@ -0,0 +1,61 @@
+# coding=utf-8
+
+import os
+import textwrap
+
+from nose.plugins.attrib import attr
+
+from conans.model.ref import ConanFileReference
+from conans.test.utils.tools import SVNLocalRepoTestCase, TestClient, \
+    load
+
+
+@attr('svn')
+class SVNTaggedComponentTest(SVNLocalRepoTestCase):
+    # Reproducing https://github.com/conan-io/conan/issues/5017
+
+    def setUp(self):
+        # Create a sample SVN repository
+        conanfile = textwrap.dedent("""
+            from conans import ConanFile, tools
+            
+            class Lib(ConanFile):
+                scm = {"type": "svn", "url": "auto", "revision": "auto"}
+        """)
+        files = {'trunk/level0.txt': "level0",
+                 'trunk/level1/level1.txt': "level1",
+                 'trunk/level1/conanfile.py': "invalid content",
+                 'tags/sentinel': ""}
+        self.project_url, rev = self.create_project(files=files)
+        self.project_url = self.project_url.replace(" ", "%20")
+
+        # Modify the recipe file and commit in trunk
+        t = TestClient()
+        t.runner('svn co "{url}/trunk" "{path}"'.format(url=self.project_url, path=t.current_folder))
+        t.save({"level1/conanfile.py": conanfile})
+        t.runner('svn commit -m "created the conanfile"', cwd=t.current_folder)
+
+        # Create a tag for 'release 1.0'
+        t.runner('svn copy {url}/trunk {url}/tags/release-1.0'
+                 ' -m "Release 1.0"'.format(url=self.project_url), cwd=t.current_folder)
+
+    def test_auto_tag(self):
+        t = TestClient()
+        ref = ConanFileReference.loads("lib/version@issue/testing")
+
+        # Clone the tag to local folder
+        url = os.path.join(self.project_url, "tags/release-1.0/level1").replace('\\', '/')
+        t.runner('svn co "{url}" "{path}"'.format(url=url, path=t.current_folder))
+        
+        # Export the recipe (be sure sources are retrieved from the repository)
+        t.run("export . {ref}".format(ref=ref))
+        package_layout = t.cache.package_layout(ref)
+        exported_conanfile = load(package_layout.conanfile())
+        self.assertNotIn("auto", exported_conanfile)
+        self.assertIn('"revision": "3",', exported_conanfile)
+        self.assertIn('tags/release-1.0/level1@3', exported_conanfile)
+        os.remove(package_layout.scm_folder())  # Just in case, avoid scm_folder optimization
+
+        # Compile (it will clone the repo)
+        t.run("install {ref} --build=lib".format(ref=ref))
+        self.assertIn("lib/version@issue/testing: Getting sources from url:", t.out)