{"id":449,"date":"2011-04-10T00:48:14","date_gmt":"2011-04-09T23:48:14","guid":{"rendered":"http:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/"},"modified":"2011-04-10T00:48:14","modified_gmt":"2011-04-09T23:48:14","slug":"how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric","status":"publish","type":"post","link":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/","title":{"rendered":"How to tag a remote git repository or&#8230; vcs support for fabric"},"content":{"rendered":"<p>With svn, you can tag a remote repository with:<\/p>\n<pre><code>svn cp <a href=\"http:\/\/\" rel=\"nofollow\" target=\"_blank\">http:\/\/<\/a>{your-svn-server}\/svn\/{project}\/trunk <a href=\"http:\/\/\" rel=\"nofollow\" target=\"_blank\">http:\/\/<\/a>{your-svn-server}\/svn\/{project}\/tags\/{tag-name}<\/code><\/pre>\n<p>or if you&#39;re already in a working copy:<\/p>\n<pre><code>svn cp ^\/{project}\/trunk ^\/{project}\/tags\/{tag-name}<\/code><\/pre>\n<p>The latter case assumes you have a working copy already checked out, but the first case is more interesting for what I needed.<\/p>\n<h2>Tagging when deploying<\/h2>\n<p>Lately I&#39;ve been working on some deployment tools in the form of a few <a href=\"http:\/\/fabfile.org\" rel=\"nofollow\">fabric<\/a> classes. One of the things I want to do when launching a production deployment is auto-tagging the repository with the new build name.<\/p>\n<p>The tag naming I went for is something like:<\/p>\n<pre><code>&lt;project_name&gt; - &lt;date&gt; - &lt;time&gt; - &lt;who_deployed&gt;<\/code><\/pre>\n<p>Example:<\/p>\n<pre><code>geodns-20110409-133701-cosimo<\/code><\/pre>\n<p>Every time there&#39;s a new production deployment using these tools, the<br \/>\nrepository \/ revision that is being deployed is tagged with names like those.<br \/>\nThe plan to use this added metadata for a &quot;deployment console&quot;, but I didn&#39;t<br \/>\nhave time to do anything about it yet.<\/p>\n<h2>vcs.py<\/h2>\n<p>Having planned the move from svn to git, I had to add a thin abstraction to the<br \/>\nfabric deployment classes to make sure that when the repository url changed from<br \/>\nsvn to git, nothing really changed from the deployment point of view.<\/p>\n<p>I ended up with a generic <code>vcs.py<\/code> class for fabric that implements vcs-related actions such as:<\/p>\n<ul>\n<li>exporting a remote repository to a local directory<\/li>\n<li>listing available tags on a remote repository<\/li>\n<li>tagging a remote repository<\/li>\n<\/ul>\n<p>This means I had to find out how to do these things in both svn and git.<\/p>\n<h3>Exporting a remote repository<\/h3>\n<p>With svn:<\/p>\n<pre><code>svn export [--force] <a href=\"http:\/\/svn.server\/project\/trunk\" rel=\"nofollow\" target=\"_blank\">http:\/\/svn.server\/project\/trunk<\/a> \/your\/local\/dir<\/code><\/pre>\n<p>and you can use <code>--force<\/code> if the local directory already exists, or svn will refuse to do it by default.<\/p>\n<p>Git requires an intermediate step:<\/p>\n<pre><code>git archive --prefix=some-dir-name\/ --remote=git.server:\/var\/git\/project.git master | tar xvC \/path\/where\/to\/export<\/code><\/pre>\n<h3>Listing available tags (remotely)<\/h3>\n<p>With svn:<\/p>\n<pre><code>svn list <a href=\"http:\/\/svn.server\/project\/tags\/\" rel=\"nofollow\" target=\"_blank\">http:\/\/svn.server\/project\/tags\/<\/a><\/code><\/pre>\n<p>With git:<\/p>\n<pre><code>git ls-remote --tags git.server:\/var\/git\/project.git<\/code><\/pre>\n<p>Thanks to my colleague Alfie for the <code>ls-remote<\/code> tip.<\/p>\n<h3>Tagging a remote URL<\/h3>\n<p>I mentioned how you do it with svn:<\/p>\n<pre><code>svn cp <a href=\"http:\/\/svn.server\/project\/trunk\" rel=\"nofollow\" target=\"_blank\">http:\/\/svn.server\/project\/trunk<\/a> <a href=\"http:\/\/svn.server\/project\/tags\/tagname\" rel=\"nofollow\" target=\"_blank\">http:\/\/svn.server\/project\/tags\/tagname<\/a><\/code><\/pre>\n<p>What about git though? I searched a bit around, and I found no git command to<br \/>\ndirectly tag a remote repository.<\/p>\n<p>I looked at the <a href=\"https:\/\/github.com\/jenkinsci\/git-plugin\" rel=\"nofollow\">Jenkins git plugin source code<\/a> but AFAICS there&#39;s no magical way to do it, so I figured out I would just clone the remote repository, tag locally and then push the tag to <code>origin<\/code>.<\/p>\n<p>In theory, this should be just fine, except it has some drawbacks:<\/p>\n<ul>\n<li><strong>Execution time<\/strong>: if the remote repository is very large, we need to clone it first, and that can take a long time.<\/li>\n<li><strong>Size<\/strong>: when cloning a large git repository, the local copy will take up disk space for nothing. We don&#39;t need it, as we just want to tag the remote repository.<\/li>\n<\/ul>\n<p>Not sure this is the best thing to do, but what I&#39;m using right now is:<\/p>\n<ul>\n<li>Cloning with <code>--depth=1<\/code>:<\/p>\n<p><code>git clone<\/code> has a <code>--depth<\/code> option that limits the amount of history that is cloned. In this case, we don&#39;t need any history, so <code>--depth=1<\/code> is great:<\/p>\n<pre><code>git clone --depth=1 &lt;git-remote-url&gt; &lt;local-dir&gt;<\/code><\/pre>\n<p>Example:<\/p>\n<pre><code>git clone --depth=1 git.server:\/var\/git\/project.git \/var\/tmp\/deploy.$USER.$$<\/code><\/pre>\n<\/li>\n<li>Tagging locally:\n<pre><code>cd \/var\/tmp\/deploy.$USER.$$\r\ngit tag -as &lt;tag-name&gt;\r\n<\/code><\/pre>\n<\/li>\n<li>Pushing the tag remotely:\n<pre><code>git push origin --tags<\/code><\/pre>\n<\/li>\n<li>Removing the temporary local copy:\n<pre><code>rm -rf \/var\/tmp\/deploy.$USER.$$<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>That&#39;s it. Not very brilliant, but works great for now. If you know of a better way to tag a remote git repository, or some existing work on these things, please get in touch or add a comment below. Thanks! :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With svn, you can tag a remote repository with: svn cp http:\/\/{your-svn-server}\/svn\/{project}\/trunk http:\/\/{your-svn-server}\/svn\/{project}\/tags\/{tag-name} or if you&#39;re already in a working copy: svn cp ^\/{project}\/trunk ^\/{project}\/tags\/{tag-name} The latter case assumes you have a working copy already checked out, but the first case is more interesting for what I needed. Tagging when deploying Lately I&#39;ve been working [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[231,91,310,121,312,309,313,311],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to tag a remote git repository or... vcs support for fabric - Random hacking<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to tag a remote git repository or... vcs support for fabric - Random hacking\" \/>\n<meta property=\"og:description\" content=\"With svn, you can tag a remote repository with: svn cp http:\/\/{your-svn-server}\/svn\/{project}\/trunk http:\/\/{your-svn-server}\/svn\/{project}\/tags\/{tag-name} or if you&#039;re already in a working copy: svn cp ^\/{project}\/trunk ^\/{project}\/tags\/{tag-name} The latter case assumes you have a working copy already checked out, but the first case is more interesting for what I needed. Tagging when deploying Lately I&#039;ve been working [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/\" \/>\n<meta property=\"og:site_name\" content=\"Random hacking\" \/>\n<meta property=\"article:published_time\" content=\"2011-04-09T23:48:14+00:00\" \/>\n<meta name=\"author\" content=\"cosimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cosimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/\"},\"author\":{\"name\":\"cosimo\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"headline\":\"How to tag a remote git repository or&#8230; vcs support for fabric\",\"datePublished\":\"2011-04-09T23:48:14+00:00\",\"dateModified\":\"2011-04-09T23:48:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/\"},\"wordCount\":527,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"keywords\":[\"deployment\",\"development\",\"fabric\",\"git\",\"remote\",\"svn\",\"tag\",\"vcs\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/\",\"name\":\"How to tag a remote git repository or... vcs support for fabric - Random hacking\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\"},\"datePublished\":\"2011-04-09T23:48:14+00:00\",\"dateModified\":\"2011-04-09T23:48:14+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to tag a remote git repository or&#8230; vcs support for fabric\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\",\"name\":\"Random hacking\",\"description\":\"Assume nothing. Code defensively. Keep it simple, stupid!\",\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\",\"name\":\"cosimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"caption\":\"cosimo\"},\"logo\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to tag a remote git repository or... vcs support for fabric - Random hacking","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/","og_locale":"en_US","og_type":"article","og_title":"How to tag a remote git repository or... vcs support for fabric - Random hacking","og_description":"With svn, you can tag a remote repository with: svn cp http:\/\/{your-svn-server}\/svn\/{project}\/trunk http:\/\/{your-svn-server}\/svn\/{project}\/tags\/{tag-name} or if you&#39;re already in a working copy: svn cp ^\/{project}\/trunk ^\/{project}\/tags\/{tag-name} The latter case assumes you have a working copy already checked out, but the first case is more interesting for what I needed. Tagging when deploying Lately I&#39;ve been working [&hellip;]","og_url":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/","og_site_name":"Random hacking","article_published_time":"2011-04-09T23:48:14+00:00","author":"cosimo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cosimo","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/#article","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/"},"author":{"name":"cosimo","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"headline":"How to tag a remote git repository or&#8230; vcs support for fabric","datePublished":"2011-04-09T23:48:14+00:00","dateModified":"2011-04-09T23:48:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/"},"wordCount":527,"commentCount":0,"publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"keywords":["deployment","development","fabric","git","remote","svn","tag","vcs"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/","url":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/","name":"How to tag a remote git repository or... vcs support for fabric - Random hacking","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website"},"datePublished":"2011-04-09T23:48:14+00:00","dateModified":"2011-04-09T23:48:14+00:00","breadcrumb":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2011\/04\/how-to-tag-a-remote-git-repository-or-vcs-support-for-fabric\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.streppone.it\/cosimo\/blog\/"},{"@type":"ListItem","position":2,"name":"How to tag a remote git repository or&#8230; vcs support for fabric"}]},{"@type":"WebSite","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website","url":"https:\/\/www.streppone.it\/cosimo\/blog\/","name":"Random hacking","description":"Assume nothing. Code defensively. Keep it simple, stupid!","publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1","name":"cosimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","caption":"cosimo"},"logo":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/449"}],"collection":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":0,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/449\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media?parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/categories?post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/tags?post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}