Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ jobs:
git config --global column.ui always
git config --global core.autocrlf false

- name: Install Python
uses: actions/setup-python@v2

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install Mercurial
run: pip install mercurial

- name: Install Crystal
uses: oprypin/install-crystal@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions spec/support/factories.cr
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ end

def create_hg_tag(project, version)
Dir.cd(hg_path(project)) do
run "hg tag #{Process.quote(version)}"
run "hg tag -u #{Process.quote("Your Name <[email protected]>")} #{Process.quote(version)}"
end
end

def create_hg_commit(project, message = "new commit")
Dir.cd(hg_path(project)) do
File.write("src/#{project}.cr", "# #{message}", mode: "a")
run "hg commit -A -m #{Process.quote(message)}"
run "hg commit -u #{Process.quote("Your Name <[email protected]>")} -A -m #{Process.quote(message)}"
end
end

Expand Down Expand Up @@ -191,7 +191,7 @@ end

def hg_commits(project, rev = ".")
Dir.cd(hg_path(project)) do
run("hg log --template='{node}\n' -r #{Process.quote(rev)}").strip.split('\n')
run("hg log --template=#{Process.quote("{node}\n")} -r #{Process.quote(rev)}").strip.split('\n')
end
end

Expand Down
25 changes: 16 additions & 9 deletions src/resolvers/hg.cr
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,23 @@ module Shards
end

protected def versions_from_tags
capture("hg tags --template '{tag}\\n'")
capture("hg tags --template #{Process.quote("{tag}\n")}")
.split('\n')
.sort!
.compact_map { |tag| Version.new($1) if tag =~ VERSION_TAG }
end

def matches?(commit)
if branch = dependency["branch"]?
!capture("hg log -r 'branch(#{tag}) and descendants(#{commit})' --template '{branch}\\n'").strip.empty?
rev = "branch(\"#{tag}\") and descendants(#{commit})"
elsif bookmark = dependency["bookmark"]?
!capture("hg log -r 'bookmark(#{bookmark}) and descendants(#{commit})' --template '{bookmarks}\\n'").strip.empty?
rev = "bookmark(\"#{bookmark}\") and descendants(#{commit})"
elsif tag = dependency["tag"]?
!capture("hg log -r 'tag(#{tag}) and descendants(#{commit})' --template '{tags}\n'").strip.empty?
rev = "tag(\"tag\") and descendants(#{commit})"
else
!capture("hg log -r #{commit}").strip.empty?
rev = commit
end
!capture("hg log -r #{Process.quote(rev)}").strip.empty?
end

def install_sources(version : Version, install_path : String)
Expand All @@ -229,7 +230,7 @@ module Shards
end

def commit_sha1_at(ref : HgRef)
capture("hg log -r #{Process.quote(ref.to_hg_ref)} --template '{node}'").strip
capture("hg log -r #{Process.quote(ref.to_hg_ref)} --template #{Process.quote("{node}\n")}").strip
end

def local_path
Expand Down Expand Up @@ -324,12 +325,18 @@ module Shards
path = local_path
FileUtils.rm_r(path) if File.exists?(path)
Dir.mkdir_p(path)
hg_retry(err: "Failed to clone #{hg_url}") do

source = hg_url
# Remove a "file://" from the beginning, otherwise the path might be invalid
# on Windows.
source = source[7..] if source.starts_with?("file://")

hg_retry(err: "Failed to clone #{source}") do
# We checkout the working directory so that "." is meaningful.
#
# An alternative would be to use the `@` bookmark, but only as long
# as nothing new is committed.
run_in_current_folder "hg clone --quiet -- #{Process.quote(hg_url)} #{Process.quote(path)}"
run_in_current_folder "hg clone --quiet -- #{Process.quote(source)} #{Process.quote(path)}"
end
end

Expand All @@ -352,7 +359,7 @@ module Shards
end

private def delete_repository
Log.debug { "rm -rf #{Process.quote(local_path)}'" }
Log.debug { "rm -rf #{Process.quote(local_path)}" }
Shards::Helpers.rm_rf(local_path)
@origin_url = nil
end
Expand Down