diff options
author | mpeterv <mpeterval@gmail.com> | 2016-02-11 17:05:30 +0300 |
---|---|---|
committer | mpeterv <mpeterval@gmail.com> | 2016-02-11 17:05:50 +0300 |
commit | 01040d6f731a8ef423f0e0a916f51616f2b1b9a1 (patch) | |
tree | 464f3812aa82ec1223a824f58aee688e18ab6a35 /src | |
parent | 137a78e3997cfb97131956d76ddb6b50bd3f8d24 (diff) | |
download | luarocks-01040d6f731a8ef423f0e0a916f51616f2b1b9a1.tar.gz luarocks-01040d6f731a8ef423f0e0a916f51616f2b1b9a1.tar.bz2 luarocks-01040d6f731a8ef423f0e0a916f51616f2b1b9a1.zip |
Add --tag option for luarocks new_version
Allows using new_version command to create tagged rockspecs
from untagged scm rockspecs. If not given, new version is copied
from passed tag, with leading 'v' stripped if it's present.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/new_version.lua | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index fb813183..6969d4b2 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua | |||
@@ -1,9 +1,7 @@ | |||
1 | 1 | ||
2 | --- Module implementing the LuaRocks "new_version" command. | 2 | --- Module implementing the LuaRocks "new_version" command. |
3 | -- Utility function that writes a new rockspec, updating data from a previous one. | 3 | -- Utility function that writes a new rockspec, updating data from a previous one. |
4 | --module("luarocks.new_version", package.seeall) | ||
5 | local new_version = {} | 4 | local new_version = {} |
6 | package.loaded["luarocks.new_version"] = new_version | ||
7 | 5 | ||
8 | local util = require("luarocks.util") | 6 | local util = require("luarocks.util") |
9 | local download = require("luarocks.download") | 7 | local download = require("luarocks.download") |
@@ -13,7 +11,7 @@ local fs = require("luarocks.fs") | |||
13 | local type_check = require("luarocks.type_check") | 11 | local type_check = require("luarocks.type_check") |
14 | 12 | ||
15 | new_version.help_summary = "Auto-write a rockspec for a new version of a rock." | 13 | new_version.help_summary = "Auto-write a rockspec for a new version of a rock." |
16 | new_version.help_arguments = "{<package>|<rockspec>} [<new_version>] [<new_url>]" | 14 | new_version.help_arguments = "[--tag=<tag>] {<package>|<rockspec>} [<new_version>] [<new_url>]" |
17 | new_version.help = [[ | 15 | new_version.help = [[ |
18 | This is a utility function that writes a new rockspec, updating data | 16 | This is a utility function that writes a new rockspec, updating data |
19 | from a previous one. | 17 | from a previous one. |
@@ -21,8 +19,10 @@ from a previous one. | |||
21 | If a package name is given, it downloads the latest rockspec from the | 19 | If a package name is given, it downloads the latest rockspec from the |
22 | default server. If a rockspec is given, it uses it instead. | 20 | default server. If a rockspec is given, it uses it instead. |
23 | 21 | ||
24 | If the version number is not given, it only increments the revision | 22 | If the version number is not given and tag is passed using --tag, |
25 | number of the given (or downloaded) rockspec. | 23 | it is used as the version, with 'v' removed from beginning. |
24 | Otherwise, it only increments the revision number of the given | ||
25 | (or downloaded) rockspec. | ||
26 | 26 | ||
27 | If a URL is given, it replaces the one from the old rockspec with the | 27 | If a URL is given, it replaces the one from the old rockspec with the |
28 | given URL. If a URL is not given and a new version is given, it tries | 28 | given URL. If a URL is not given and a new version is given, it tries |
@@ -30,6 +30,9 @@ to guess the new URL by replacing occurrences of the version number | |||
30 | in the URL or tag. It also tries to download the new URL to determine | 30 | in the URL or tag. It also tries to download the new URL to determine |
31 | the new MD5 checksum. | 31 | the new MD5 checksum. |
32 | 32 | ||
33 | If a tag is given, it replaces the one from the old rockspec. If there is | ||
34 | an old tag but no new one passed, it is guessed in the same way URL is. | ||
35 | |||
33 | WARNING: it writes the new rockspec to the current directory, | 36 | WARNING: it writes the new rockspec to the current directory, |
34 | overwriting the file if it already exists. | 37 | overwriting the file if it already exists. |
35 | ]] | 38 | ]] |
@@ -85,7 +88,10 @@ local function check_url_and_update_md5(out_rs) | |||
85 | end | 88 | end |
86 | end | 89 | end |
87 | 90 | ||
88 | local function update_source_section(out_rs, url, old_ver, new_ver) | 91 | local function update_source_section(out_rs, url, tag, old_ver, new_ver) |
92 | if tag then | ||
93 | out_rs.source.tag = tag | ||
94 | end | ||
89 | if url then | 95 | if url then |
90 | out_rs.source.url = url | 96 | out_rs.source.url = url |
91 | return check_url_and_update_md5(out_rs) | 97 | return check_url_and_update_md5(out_rs) |
@@ -102,7 +108,7 @@ local function update_source_section(out_rs, url, old_ver, new_ver) | |||
102 | if try_replace(out_rs.source, "url", old_ver, new_ver) then | 108 | if try_replace(out_rs.source, "url", old_ver, new_ver) then |
103 | return check_url_and_update_md5(out_rs) | 109 | return check_url_and_update_md5(out_rs) |
104 | end | 110 | end |
105 | if try_replace(out_rs.source, "tag", old_ver, new_ver) then | 111 | if tag or try_replace(out_rs.source, "tag", old_ver, new_ver) then |
106 | return true | 112 | return true |
107 | end | 113 | end |
108 | -- Couldn't replace anything significant, use the old URL. | 114 | -- Couldn't replace anything significant, use the old URL. |
@@ -139,6 +145,10 @@ function new_version.run(...) | |||
139 | 145 | ||
140 | local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") | 146 | local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") |
141 | local new_ver, new_rev | 147 | local new_ver, new_rev |
148 | |||
149 | if flags.tag and not version then | ||
150 | version = flags.tag:gsub("^v", "") | ||
151 | end | ||
142 | 152 | ||
143 | if version then | 153 | if version then |
144 | new_ver, new_rev = version:match("(.*)%-(%d+)$") | 154 | new_ver, new_rev = version:match("(.*)%-(%d+)$") |
@@ -157,7 +167,7 @@ function new_version.run(...) | |||
157 | local out_name = out_rs.package:lower() | 167 | local out_name = out_rs.package:lower() |
158 | out_rs.version = new_rockver.."-"..new_rev | 168 | out_rs.version = new_rockver.."-"..new_rev |
159 | 169 | ||
160 | local ok, err = update_source_section(out_rs, url, old_ver, new_ver) | 170 | local ok, err = update_source_section(out_rs, url, flags.tag, old_ver, new_ver) |
161 | if not ok then return nil, err end | 171 | if not ok then return nil, err end |
162 | 172 | ||
163 | if out_rs.build and out_rs.build.type == "module" then | 173 | if out_rs.build and out_rs.build.type == "module" then |