author | Jan Vrany <jan.vrany@labware.com> |
Mon, 31 Jul 2023 11:41:28 +0100 | |
changeset 336 | b31bb339d800 |
parent 321 | c868ba75e2da |
permissions | -rw-r--r-- |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
1 |
# This file is not a standalone script. It is a kind |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
2 |
# of lightweight Mercurial library used by other scripts. |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
3 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
4 |
require 'uri' |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
5 |
require 'open3' |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
6 |
require 'shellwords' |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
7 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
8 |
# Following hack is to make hglib.rb working wit both jv:scripts and |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
9 |
# Smalltalk/X rakefiles. |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
10 |
begin |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
11 |
require 'rakelib/inifile' |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
12 |
rescue |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
13 |
begin |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
14 |
require 'inifile' |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
15 |
rescue LoadError => ex |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
16 |
$LOGGER.error(%q{Cannot load package 'inifile'}) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
17 |
$LOGGER.error(%q{Run 'gem install inifile' to install it}) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
18 |
exit 1 |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
19 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
20 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
21 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
22 |
unless $LOGGER |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
23 |
if STDOUT.tty? or win32? |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
24 |
require 'logger' |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
25 |
$LOGGER = Logger.new(STDOUT) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
26 |
|
301 | 27 |
if defined? VERBOSE and !VERBOSE.nil? |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
28 |
$LOGGER.level = Logger::DEBUG |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
29 |
else |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
30 |
$LOGGER.level = Logger::INFO |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
31 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
32 |
else |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
33 |
require 'syslog/logger' |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
34 |
$LOGGER = Syslog::Logger.new($0) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
35 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
36 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
37 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
38 |
module HG |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
39 |
@@config = nil |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
40 |
|
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
41 |
class Exception < ::Exception |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
42 |
end |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
43 |
|
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
44 |
class RepositoryNotFoundException < Exception |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
45 |
end |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
46 |
|
86
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
47 |
# Cross-platform way of finding an executable in the $PATH. |
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
48 |
# |
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
49 |
# which('ruby') #=> /usr/bin/ruby |
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
50 |
module_function |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
51 |
|
86
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
52 |
def which(cmd) |
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
53 |
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] |
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
54 |
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
55 |
exts.each {|ext| |
86
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
56 |
exe = File.join(path, "#{cmd}#{ext}") |
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
57 |
return exe if File.executable?(exe) && !File.directory?(exe) |
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
58 |
} |
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
59 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
60 |
nil |
86
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
61 |
end |
f2a7a4378c22
Added task `workflow:merge' to ease merging code from eXept
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
85
diff
changeset
|
62 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
63 |
GLOBAL_OPTIONS = %i(cwd repository noninteractive config debug debugger encoding |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
64 |
encodingmode traceback time profile version help hidden |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
65 |
) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
66 |
|
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
67 |
# Execute `hg` command with given positional arguments and |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
68 |
# keyword arguments turned into command options. For example, |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
69 |
# |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
70 |
# HG::hg("heads", "default", cwd: '/tmp/testrepo') |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
71 |
# |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
72 |
# will result in executing |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
73 |
# |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
74 |
# hg --cwd '/tmp/testrepo' heads default |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
75 |
# |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
76 |
# In addition if block is passed, then the block is evaluate with |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
77 |
# `hg` command exit status (as Process::Status) and (optionally) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
78 |
# with contents of `hg` command stdout and stderr. |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
79 |
# If no block is given, an exception is raised when `hg` command |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
80 |
# exit status IS NOT zero. |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
81 |
def self.hg(command, *args, **options, &block) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
82 |
g_opts = [] |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
83 |
c_opts = [] |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
84 |
options.each do |k, v| |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
85 |
if v != false and !v.nil? |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
86 |
o = k.size == 1 ? "-#{k}" : "--#{k}" |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
87 |
if GLOBAL_OPTIONS.include? k |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
88 |
if v.is_a?(Array) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
89 |
v.each do |e| |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
90 |
g_opts << o << (e == true ? '' : e) # bug ruby: e ? '' : e does not work correctly |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
91 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
92 |
else |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
93 |
g_opts << o << (v == true ? '' : v) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
94 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
95 |
else |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
96 |
if v.is_a?(Array) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
97 |
v.each do |e| |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
98 |
c_opts << o << (e == true ? '' : e) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
99 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
100 |
else |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
101 |
c_opts << o << (v == true ? '' : v) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
102 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
103 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
104 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
105 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
106 |
c_opts.reject! {|e| e.size == 0} |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
107 |
cmd = ['hg'] + g_opts + [command] + c_opts + args |
68
61d8bee7c4d4
Added new tasks - `workflow:push-upstream` and `workflow:push-staging`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
67
diff
changeset
|
108 |
cmd_info = cmd.shelljoin. |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
109 |
gsub(/username\\=\S+/, "username\\=***"). |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
110 |
gsub(/password\\=\S+/, "password\\=***") |
68
61d8bee7c4d4
Added new tasks - `workflow:push-upstream` and `workflow:push-staging`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
67
diff
changeset
|
111 |
$LOGGER.debug("executing: #{cmd_info}") |
138 | 112 |
if defined? RakeFileUtils and RakeFileUtils.verbose; puts cmd_info; end |
113 |
||
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
114 |
if block_given? |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
115 |
stdout, stderr, status = Open3.capture3(*cmd) |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
116 |
# For command that deal with remotes, handle check whether the failure |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
117 |
# is because of missing remote repository. If so, raise exception. |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
118 |
if status.exitstatus == 255 |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
119 |
if stdout =~ /remote:\ *Repository.*not found/ or stderr =~ /abort:.*HTTP.*404/ |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
120 |
raise RepositoryNotFoundException.new("Remote repository not found!") |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
121 |
end |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
122 |
end |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
123 |
|
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
124 |
case block.arity |
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
125 |
when 1 |
228
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
126 |
STDOUT.print stdout if defined? RakeFileUtils and RakeFileUtils.verbose |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
127 |
STDERR.print stderr if defined? RakeFileUtils and RakeFileUtils.verbose |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
128 |
yield status |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
129 |
when 2 |
228
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
130 |
STDERR.print stderr if defined? RakeFileUtils and RakeFileUtils.verbose |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
131 |
yield status, stdout |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
132 |
when 3 |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
133 |
yield status, stdout, stderr |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
134 |
else |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
135 |
raise Exception.new("invalid arity of given block") |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
136 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
137 |
else |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
138 |
raise Exception.new("command failed: #{cmd.join(' ')}") unless system(*cmd) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
139 |
end |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
140 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
141 |
|
321
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
142 |
def self.config_file(dir, nm) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
143 |
path = File.join(dir, nm) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
144 |
if File.exist?(path) then |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
145 |
return [ path ] |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
146 |
else |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
147 |
return [ ] |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
148 |
end |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
149 |
end |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
150 |
|
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
151 |
def self.config_dir(dir, nm) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
152 |
path = File.join(dir, nm) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
153 |
if File.directory?(path) then |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
154 |
return Dir.glob("#{path}\\*.rc".gsub('\\', '/')) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
155 |
else |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
156 |
return [ ] |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
157 |
end |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
158 |
end |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
159 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
160 |
def self.config |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
161 |
if @@config.nil? |
321
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
162 |
files = [] |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
163 |
files += HG::config_dir('/etc/mercurial', 'hgrc.d') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
164 |
files += HG::config_file('/etc/mercurial', 'hgrc') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
165 |
files += [ hgrc ] |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
166 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
167 |
if Gem.win_platform? |
321
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
168 |
# An excerpt from `hg help config`: |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
169 |
# On Windows, the following files are consulted: |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
170 |
|
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
171 |
# - "<repo>/.hg/hgrc" (per-repository) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
172 |
# - "%USERPROFILE%\.hgrc" (per-user) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
173 |
# - "%USERPROFILE%\Mercurial.ini" (per-user) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
174 |
# - "%HOME%\.hgrc" (per-user) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
175 |
# - "%HOME%\Mercurial.ini" (per-user) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
176 |
# - "HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial" (per-system) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
177 |
# - "<install-dir>\hgrc.d\*.rc" (per-installation) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
178 |
# - "<install-dir>\Mercurial.ini" (per-installation) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
179 |
# - "%PROGRAMDATA%\Mercurial\hgrc" (per-system) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
180 |
# - "%PROGRAMDATA%\Mercurial\Mercurial.ini" (per-system) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
181 |
# - "%PROGRAMDATA%\Mercurial\hgrc.d\*.rc" (per-system) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
182 |
# - "<internal>/*.rc" (defaults) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
183 |
|
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
184 |
files += HG::config_file(ENV['USERPROFILE'], '.hgrc') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
185 |
files += HG::config_file(ENV['USERPROFILE'], 'Mercurial.ini') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
186 |
|
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
187 |
files += HG::config_file(ENV['HOME'], '.hgrc') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
188 |
files += HG::config_file(ENV['HOME'], 'Mercurial.ini') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
189 |
|
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
190 |
install_dir = File.dirname(HG::which("hg")) |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
191 |
files += HG::config_dir( install_dir, 'hgrc.d') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
192 |
files += HG::config_file(install_dir, 'Mercurial.ini') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
193 |
|
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
194 |
files += HG::config_file(ENV['PROGRAMDATA'], '.hgrc') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
195 |
files += HG::config_file(ENV['PROGRAMDATA'], 'Mercurial.ini') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
196 |
files += HG::config_dir( ENV['PROGRAMDATA'], 'hgrc.d') |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
197 |
|
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
198 |
# Following is used by recent TortoiseHg |
c868ba75e2da
Rakefiles: improve (fix) Mercurial config reading on Windows
Jan Vrany <jan.vrany@labware.com>
parents:
307
diff
changeset
|
199 |
files += HG::config_dir( install_dir, 'defaultrc') |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
200 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
201 |
@@config = IniFile.new |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
202 |
files.each do |file| |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
203 |
if File.exist?(file) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
204 |
$LOGGER.debug("Loading global config from \"#{file}\"") |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
205 |
@@config.merge!(IniFile.new(:filename => file)) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
206 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
207 |
end |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
208 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
209 |
return @@config |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
210 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
211 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
212 |
def self.hgrc |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
213 |
return File.expand_path('~/.hgrc') |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
214 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
215 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
216 |
class Repository |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
217 |
@@HOSTS_ON_LAN = {} |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
218 |
|
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
219 |
attr_accessor :path, :config |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
220 |
|
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
221 |
|
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
222 |
private |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
223 |
# Return --ssh config string for use with passed remote url or nil |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
224 |
# if no special --ssh config is needed. |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
225 |
# |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
226 |
# This is used to tweak SSH connection in various ways, but only |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
227 |
# when `ui.ssh` is not set (or has default value on Windows, see below). |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
228 |
# |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
229 |
# Following tweaks are done: |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
230 |
# |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
231 |
# 1. On Windows, prefer MSYS2's `ssh.exe` over `plink.exe`. |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
232 |
# |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
233 |
# Most of users tend to use TortoiseHG and hg.exe comming with |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
234 |
# it. THG makes hg.exe to use (shipped) plink.exe which is bad for performance |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
235 |
# since it uses 16k channel input buffer (!) leading to a pretty slow transfers |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
236 |
# (a lot of iowaits...) |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
237 |
# OpenSSH OTOH has 2MB input buffer which is good though on Windows bit |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
238 |
# oversized as Windows TCP window size is fixed to 65k for all connections with |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
239 |
# RTT less than 1ms. Still, 65k better then 16k. |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
240 |
# As a workaround, look if MSYS2's OpenSSH client is installed and if so, use that |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
241 |
# one - but only if `ui.ssh` config option has the default value. |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
242 |
# Ugly, isn't it? |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
243 |
# |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
244 |
# 2. If cloning / updating over LAN and using openssh client, add `-C` option to disable compression. |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
245 |
# |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
246 |
# Data transferred by Mercurial are either already compressed or --uncompressed |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
247 |
# was given to reduce CPU load in which case passing -C would reduce it further. |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
248 |
# |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
249 |
# 3. If cloning / updating non-interactively (from scripts or on CI servers), pass |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
250 |
# `-o "StrictHostKeyChecking off"`. |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
251 |
# |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
252 |
# This is to avoid failures on CI due to missing / changed host key. Not the best, |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
253 |
# but otherwise we'd have to configure each and every slave's `.ssh/config` |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
254 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
255 |
def self.sshconf(uri_string) |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
256 |
uri = URI(uri_string) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
257 |
ssh = nil |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
258 |
if uri.scheme == 'ssh' |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
259 |
ssh_in_path = HG::which('ssh') |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
260 |
ssh_in_hgrc = HG::config['ui']['ssh'] |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
261 |
if Gem.win_platform? |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
262 |
# Running on Windows |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
263 |
# |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
264 |
# On Windows, MSYS's ssh.exe may not be in the path. Check standard place |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
265 |
# and update `ssh_in_path` |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
266 |
if ssh_in_path == nil and File.exist? %q{c:\msys64\usr\bin\ssh.exe} then |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
267 |
ssh_in_path = %q{"c:\msys64\usr\bin\ssh.exe"} |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
268 |
end |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
269 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
270 |
# Mercurial uses `ssh` by default, so to use `plink.exe`, `ui.ssh` |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
271 |
# config option has to be explicitly set. |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
272 |
# |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
273 |
# It it's set to `plink.exe`, check whether MSYS's `ssh.exe` is available |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
274 |
# and if so, change it to `ssh.exe`... |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
275 |
if /^.*[pP]link.exe"?\s*(-ssh)?\s*(-2)?$/ =~ ssh_in_hgrc |
85
6d918f722075
Do not tamper with SSH configuration if SSH agent is not running.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
83
diff
changeset
|
276 |
# Sigh, we should not tamper with SSH configuration wildly. User may have |
6d918f722075
Do not tamper with SSH configuration if SSH agent is not running.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
83
diff
changeset
|
277 |
# her ssh and mercurial properly configured to use `plink.exe` and `pageant`. |
6d918f722075
Do not tamper with SSH configuration if SSH agent is not running.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
83
diff
changeset
|
278 |
# If we just start using `ssh.exe` clone/pull might not work beause |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
279 |
# `ssh.exe` cannot talk to `pageant`. So, if we don't find OpenSSH's |
85
6d918f722075
Do not tamper with SSH configuration if SSH agent is not running.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
83
diff
changeset
|
280 |
# style of agent, don't use `ssh.exe` event if available. |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
281 |
if ssh_in_path |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
282 |
if ENV['SSH_AUTH_SOCK'] |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
283 |
ssh = ssh_in_path |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
284 |
else |
85
6d918f722075
Do not tamper with SSH configuration if SSH agent is not running.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
83
diff
changeset
|
285 |
# No agent, no fun. Be nice and give user a hit |
6d918f722075
Do not tamper with SSH configuration if SSH agent is not running.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
83
diff
changeset
|
286 |
$LOGGER.warn("Not using -ssh \"#{ssh}\" option because SSH agent is not running") |
6d918f722075
Do not tamper with SSH configuration if SSH agent is not running.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
83
diff
changeset
|
287 |
$LOGGER.warn("For faster clone/pull consider using ssh-agent or ssh-pageant (if you want to use PuTTY's pageant)") |
6d918f722075
Do not tamper with SSH configuration if SSH agent is not running.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
83
diff
changeset
|
288 |
ssh = nil |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
289 |
end |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
290 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
291 |
end |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
292 |
else |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
293 |
# Running on UNIX (actually, anything but Windows) |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
294 |
# |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
295 |
# Check if ui.ssh is configured, if not, use custom SSH command. |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
296 |
# Here we set `ssh` to non-nil value only to pass it through nil-checks |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
297 |
# below... |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
298 |
ssh = ssh_in_path |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
299 |
end |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
300 |
|
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
301 |
if ssh |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
302 |
ssh += " -C" if ssh and HG::Repository::host_on_lan?(uri.host) |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
303 |
ssh += " -o 'StrictHostKeyChecking off'" if not STDOUT.isatty |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
304 |
end |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
305 |
end |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
306 |
|
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
307 |
# Be nice and tell the user if SSH configuration has been tampered wirh. |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
308 |
$LOGGER.info("Passing --ssh \"#{ssh}\" option to 'hg' command for faster transfers") if ssh |
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
309 |
|
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
310 |
# Done, tricky, wasn't it? |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
311 |
return ssh |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
312 |
end |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
313 |
|
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
314 |
# Same as class method, but allows for remote aliases |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
315 |
def sshconf(remote) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
316 |
HG::Repository::sshconf(self.paths[remote] || remote) |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
317 |
end |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
318 |
|
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
319 |
# Given a hostname, return true if the host is on local LAN, false |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
320 |
# otherwise. |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
321 |
# |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
322 |
# Results are cached to reduce resolver queries (maybe not worth it, |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
323 |
# system may cache answers anyways) |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
324 |
# |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
325 |
# The detection is rather simplistic - it only checks if host's address |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
326 |
# is from private IP range - and only for IPv4. |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
327 |
# This may cause problems when using over VPN that assigns private address |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
328 |
# (the usuall case). In that case this code will treat is a local |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
329 |
# which may result in transfer of uncompressed data over WAN. Not nice, |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
330 |
# This should be fixed, somehow. |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
331 |
def self.host_on_lan?(hostname) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
332 |
unless @@HOSTS_ON_LAN.has_key? hostname |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
333 |
require 'resolv' |
301 | 334 |
local = false |
335 |
begin |
|
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
336 |
addr = Resolv.getaddress(hostname) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
337 |
# Really poor detection of LAN, but since this is an |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
338 |
# optimization, getting this wrong does not hurt. |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
339 |
local = (addr.start_with? '192.168.') or (addr.start_with? '10.10.') |
301 | 340 |
rescue ArgumentError => ex |
341 |
# Maybe not a remote host at all |
|
342 |
local = false |
|
343 |
end |
|
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
344 |
@@HOSTS_ON_LAN[hostname] = local |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
345 |
end |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
346 |
return @@HOSTS_ON_LAN[hostname] |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
347 |
end |
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
348 |
|
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
349 |
public |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
350 |
# Clone a repository from given `uri` to given `directory`. |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
351 |
# Returns an `HG::Repository` instance representing the repository |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
352 |
# clone. |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
353 |
# If `noupdate` is true, working copy is not updated, i.e., will be |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
354 |
# empty. Use this when you're going to issue `update(rev)` shortly after. |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
355 |
# |
101
32f9287b419a
Cleanup: Nuked leftover code for using BCC 5.5.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
89
diff
changeset
|
356 |
def self.clone(uri, directory, noupdate: false, publishing: false) |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
357 |
uri_obj = URI(uri) |
76
df28d45f7f5a
On Windows use MSYS2 `ssh.exe` rather than `plink.exe` to clone/checkout repositories over SSH
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
75
diff
changeset
|
358 |
host = uri_obj.host |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
359 |
scheme = uri_obj.scheme |
75
9b57c88b2ab3
Use `hg clone` instead of `hg init` followed by `hg pull` to checkout a Mercurial repository
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
360 |
# When cloning over LAN, use --uncompressed option |
9b57c88b2ab3
Use `hg clone` instead of `hg init` followed by `hg pull` to checkout a Mercurial repository
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
73
diff
changeset
|
361 |
# as it tends to be faster if bandwidth is good (1GB norm |
76
df28d45f7f5a
On Windows use MSYS2 `ssh.exe` rather than `plink.exe` to clone/checkout repositories over SSH
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
75
diff
changeset
|
362 |
# these days) amd saves some CPU cycles. |
83
8405c22a8ffd
Use customized ssh command for all commands involving data transfer (in addition to `clone`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
79
diff
changeset
|
363 |
local = HG::Repository::host_on_lan?(URI(uri).host) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
364 |
ssh = HG::Repository::sshconf(uri) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
365 |
|
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
366 |
HG::hg('clone', uri, directory, ssh: ssh, uncompressed: local, noupdate: noupdate, config: "phases.publish=#{publishing}") |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
367 |
return HG::Repository.new(directory) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
368 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
369 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
370 |
# Initializes an empty repository in given directory. Returns an |
67
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
371 |
# `HG::Repository` instance representing the created (empty) repository. |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
372 |
# TODO: unreachable code!!! |
67
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
373 |
def self.init(directory) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
374 |
HG::hg('init', directory) |
67
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
375 |
return HG::Repository.new(directory) |
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
376 |
end |
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
377 |
|
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
378 |
# Like HG::hg, but passes --cwd @path |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
379 |
def hg(command, *args, **options, &block) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
380 |
options[:cwd] = @path |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
381 |
HG::hg(command, *args, **options, &block) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
382 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
383 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
384 |
def hgrc |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
385 |
File.join(@path, '.hg', 'hgrc') |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
386 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
387 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
388 |
def initialize(directory) |
234
05943c900d5e
Rakefiles: added new target `artifacts:source`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
228
diff
changeset
|
389 |
dir = File.expand_path(directory) |
05943c900d5e
Rakefiles: added new target `artifacts:source`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
228
diff
changeset
|
390 |
if not File.exist?(File.join(dir, '.hg')) |
05943c900d5e
Rakefiles: added new target `artifacts:source`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
228
diff
changeset
|
391 |
raise Exception.new("Not a Mercurial repository (missing .hg directory): #{dir}") |
05943c900d5e
Rakefiles: added new target `artifacts:source`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
228
diff
changeset
|
392 |
end |
05943c900d5e
Rakefiles: added new target `artifacts:source`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
228
diff
changeset
|
393 |
@path = dir |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
394 |
initialize_config |
120
2c4e52c4c930
Do not use `hg clone ...` to create and pull changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
101
diff
changeset
|
395 |
end |
2c4e52c4c930
Do not use `hg clone ...` to create and pull changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
101
diff
changeset
|
396 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
397 |
def initialize_config |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
398 |
config_file = hgrc |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
399 |
if File.exist? (config_file) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
400 |
$LOGGER.debug("Loading repository config from \"#{config_file}\"") |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
401 |
@config = HG::config().merge(IniFile.new(:filename => config_file)) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
402 |
else |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
403 |
@config = HG::config() |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
404 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
405 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
406 |
|
120
2c4e52c4c930
Do not use `hg clone ...` to create and pull changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
101
diff
changeset
|
407 |
# Add / replace given config options and write back |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
408 |
# .hg/hgrc |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
409 |
def config_set(**options) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
410 |
config = IniFile.new(:filename => self.hgrc) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
411 |
options.each do |section, keys_and_values| |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
412 |
keys_and_values.each {|key, value| config[section][key] = value.to_s} |
120
2c4e52c4c930
Do not use `hg clone ...` to create and pull changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
101
diff
changeset
|
413 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
414 |
config.write |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
415 |
initialize_config |
120
2c4e52c4c930
Do not use `hg clone ...` to create and pull changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
101
diff
changeset
|
416 |
end |
2c4e52c4c930
Do not use `hg clone ...` to create and pull changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
101
diff
changeset
|
417 |
|
67
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
418 |
# Return a hashmap with defined paths (alias => uri) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
419 |
def paths |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
420 |
@config['paths'].clone |
67
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
421 |
end |
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
422 |
|
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
423 |
# Set paths for given repository |
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
424 |
def paths=(paths) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
425 |
config_set(paths: paths) |
67
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
426 |
end |
75b6eb7b781c
Added support for canonical, upstream and staging repositores.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
66
diff
changeset
|
427 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
428 |
def log(revset, template = "{node|short}\n") |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
429 |
log = [] |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
430 |
hg('log', rev: revset, template: template) do |status, out| |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
431 |
if status.success? |
228
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
432 |
puts out if defined? RakeFileUtils and RakeFileUtils.verbose |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
433 |
log = out.split("\n") |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
434 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
435 |
end |
228
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
436 |
return log |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
437 |
end |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
438 |
|
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
439 |
def locate(revset = '.', pattern: '*') |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
440 |
files = [] |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
441 |
hg('locate', rev: revset, include: pattern) do |status, out| |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
442 |
if status.success? |
228
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
443 |
files = out.split("\n") |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
444 |
end |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
445 |
end |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
446 |
return files |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
447 |
end |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
448 |
|
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
449 |
# Return current branch name |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
450 |
def branch() |
228
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
451 |
hg('branch') do | status, out | |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
452 |
if status.success? |
228
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
453 |
return out.strip() |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
454 |
end |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
455 |
end |
8566593080a5
hglib: added `HG::Repository#branch()` and `HG::Repository#locate()`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
220
diff
changeset
|
456 |
raise Exception.new("Failed to retrieve current branch") |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
457 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
458 |
|
302
ae5685abab0a
Rakefiles: do not include obsolete changesets in `HGRepository::heads()`
Jan Vrany <jan.vrany@labware.com>
parents:
301
diff
changeset
|
459 |
# Return changeset IDs of all head revisions. |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
460 |
# If `branch` is given, return only heads in given |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
461 |
# branch. |
302
ae5685abab0a
Rakefiles: do not include obsolete changesets in `HGRepository::heads()`
Jan Vrany <jan.vrany@labware.com>
parents:
301
diff
changeset
|
462 |
# If `secret_secret` is false, then changesets in |
ae5685abab0a
Rakefiles: do not include obsolete changesets in `HGRepository::heads()`
Jan Vrany <jan.vrany@labware.com>
parents:
301
diff
changeset
|
463 |
# secret phase are ignored (even if they're heads) |
ae5685abab0a
Rakefiles: do not include obsolete changesets in `HGRepository::heads()`
Jan Vrany <jan.vrany@labware.com>
parents:
301
diff
changeset
|
464 |
# If `secret_obsolete` is true, then obsolete changesets |
ae5685abab0a
Rakefiles: do not include obsolete changesets in `HGRepository::heads()`
Jan Vrany <jan.vrany@labware.com>
parents:
301
diff
changeset
|
465 |
# are ignored (even if they're heads) |
ae5685abab0a
Rakefiles: do not include obsolete changesets in `HGRepository::heads()`
Jan Vrany <jan.vrany@labware.com>
parents:
301
diff
changeset
|
466 |
def heads(branch = nil, include_secret: true, include_obsolete: false) |
220
8faa459a7ee9
Rakefiles: do not consider secret changesets as heads when updating
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
148
diff
changeset
|
467 |
revset = "head()" |
8faa459a7ee9
Rakefiles: do not consider secret changesets as heads when updating
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
148
diff
changeset
|
468 |
revset += " and branch('#{branch}')" if branch |
8faa459a7ee9
Rakefiles: do not consider secret changesets as heads when updating
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
148
diff
changeset
|
469 |
revset += " and !secret()" if not include_secret |
302
ae5685abab0a
Rakefiles: do not include obsolete changesets in `HGRepository::heads()`
Jan Vrany <jan.vrany@labware.com>
parents:
301
diff
changeset
|
470 |
revset += " and !obsolete()" if not include_secret |
220
8faa459a7ee9
Rakefiles: do not consider secret changesets as heads when updating
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
148
diff
changeset
|
471 |
return log(revset) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
472 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
473 |
|
72
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
474 |
# Return name of an active bookmark or nil if no bookmark |
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
475 |
# is active |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
476 |
def bookmark |
72
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
477 |
filename = File.join(@path, '.hg', 'bookmarks.current') |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
478 |
if File.exist?(filename) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
479 |
file = File.open(filename, 'r') |
72
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
480 |
begin |
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
481 |
bookmark = file.read.chomp |
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
482 |
ensure |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
483 |
file.close |
72
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
484 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
485 |
bookmark |
72
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
486 |
else |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
487 |
nil |
72
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
488 |
end |
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
489 |
end |
3e832d54a4af
Added support for checking out a particular revision
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
71
diff
changeset
|
490 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
491 |
# Return a hash "bookmark => revision" of all |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
492 |
# bookmarks. |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
493 |
def bookmarks(branch = nil) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
494 |
revset = 'bookmark()' |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
495 |
revset += " and branch('#{branch}')" if branch |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
496 |
bookmarks = {} |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
497 |
self.log(revset, "{bookmarks}|{node|short}\n").each do |line| |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
498 |
bookmarks_per_changeset, changesetid = line.split('|') |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
499 |
bookmarks_per_changeset.split(' ').each {|bookmark| bookmarks[bookmark] = changesetid} |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
500 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
501 |
bookmarks |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
502 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
503 |
|
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
504 |
# a private helper to generate auth --config options for |
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
505 |
# HTTP-served repositories |
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
506 |
protected |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
507 |
def authconf(remote, user, pass) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
508 |
authconf = [] |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
509 |
unless pass.nil? |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
510 |
raise Exception.new('Password given but not username! Use user: named param to specify username.') if user.nil? |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
511 |
# If user/password is provided, make sure we don't have |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
512 |
# username in remote URI. Otherwise Mercurial won't use |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
513 |
# password from config! |
71
68c8cccbdec5
Cleanup in `scm.rb`: Unified API of `checkout` and `update` functions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
68
diff
changeset
|
514 |
uri = URI.parse(self.paths[remote] || remote) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
515 |
uri.user = nil |
71
68c8cccbdec5
Cleanup in `scm.rb`: Unified API of `checkout` and `update` functions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
68
diff
changeset
|
516 |
uri = uri.to_s |
336
b31bb339d800
Rakefiles: fix `HG::Repository#autoconf`
Jan Vrany <jan.vrany@labware.com>
parents:
321
diff
changeset
|
517 |
uri_alias = self.paths[remote] || 'xxx' |
71
68c8cccbdec5
Cleanup in `scm.rb`: Unified API of `checkout` and `update` functions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
68
diff
changeset
|
518 |
authconf << "auth.#{uri_alias}.prefix=#{uri}" |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
519 |
authconf << "auth.#{uri_alias}.username=#{user}" |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
520 |
authconf << "auth.#{uri_alias}.password=#{pass}" |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
521 |
end |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
522 |
authconf |
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
523 |
end |
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
524 |
|
269
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
525 |
# Return true, if given remote is known to be shaky, i.e., randomly failing. |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
526 |
# BitBucket is known to be very, very shaky recently (since summer 2919(). |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
527 |
def shaky_remote?(remote) |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
528 |
remote_url = @config['paths'][remote] || remote |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
529 |
return remote_url =~ /bitbucket.org/ |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
530 |
end |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
531 |
|
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
532 |
def pull1(remote = 'default', user: nil, pass: nil, rev: nil, bookmarks: nil) |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
533 |
hg('pull', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev, bookmark: bookmarks) do |status, stdout, stderr | |
269
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
534 |
STDOUT.print stdout |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
535 |
case status.exitstatus |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
536 |
when 0 |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
537 |
#nothing |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
538 |
when 1 |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
539 |
raise Exception.new("Failed to 'pull' from #{remote} (update had unresolved conflicts)") |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
540 |
else |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
541 |
STDERR.print stderr |
269
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
542 |
raise Exception.new("Failed to 'pull' from #{remote} (exit code #{status.exitstatus})") |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
543 |
end |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
544 |
end |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
545 |
end |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
546 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
547 |
public |
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
548 |
|
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
549 |
def incoming(remote = 'default', user: nil, pass: nil, rev: nil) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
550 |
hg('incoming', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev) do |status, stdout| |
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
551 |
case status.exitstatus |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
552 |
when 0 |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
553 |
STDOUT.print stdout |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
554 |
when 1 |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
555 |
puts "No new changes coming from #{remote}" |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
556 |
else |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
557 |
STDERR.print stderr |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
558 |
raise Exception.new("Failed to do 'incoming' from #{remote} (exit code #{status.exitstatus})") |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
559 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
560 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
561 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
562 |
|
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
563 |
def pull(remote = 'default', user: nil, pass: nil, rev: nil, bookmarks: nil) |
269
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
564 |
if not shaky_remote?(remote) |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
565 |
pull1(remote, user: user, pass: pass, rev: rev, bookmarks: bookmarks) |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
566 |
else |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
567 |
# Remote is shaky, try to pull, if pull fails, wait some time and retry |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
568 |
# again. See #shaky_remote?() |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
569 |
begin |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
570 |
pull1(remote, user: user, pass: pass, rev: rev, bookmarks: bookmarks) |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
571 |
rescue RepositoryNotFoundException => rnfe |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
572 |
raise rnfe |
269
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
573 |
rescue Exception |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
574 |
delay = 30 + rand * 100 |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
575 |
puts "Oops, remote is shaky, retrying after #{delay}" |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
576 |
sleep(delay) |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
577 |
begin |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
578 |
pull1(remote, user: user, pass: pass, rev: rev, bookmarks: bookmarks) |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
579 |
rescue Exception |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
580 |
delay = 30 + rand * 100 |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
581 |
puts "Oops, remote is shaky, retrying after #{delay}" |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
582 |
sleep(delay) |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
583 |
pull1(remote, user: user, pass: pass, rev: rev, bookmarks: bookmarks) |
e6ccd5be9bcb
Rakefiles: move retrying code from `scm.rb` to `hglib.rb`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
234
diff
changeset
|
584 |
end |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
585 |
end |
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
586 |
end |
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
587 |
end |
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
588 |
|
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
589 |
def outgoing(remote = 'default', user: nil, pass: nil, rev: nil, &block) |
138 | 590 |
if !block_given? |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
591 |
hg('outgoing', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev) do |status, stdout, stderr| |
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
592 |
STDOUT.print stdout |
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
593 |
case status.exitstatus |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
594 |
when 0 |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
595 |
# notning |
127
664296ccdb4a
Improved tasks `workflow:out-staging` and `workflow:out-upstream`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
124
diff
changeset
|
596 |
when 1 |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
597 |
puts "No new changes going to #{remote}" |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
598 |
else |
272
13ce86e80c30
Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
269
diff
changeset
|
599 |
STDERR.print stderr |
127
664296ccdb4a
Improved tasks `workflow:out-staging` and `workflow:out-upstream`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
124
diff
changeset
|
600 |
raise Exception.new("Failed to do 'outgoing' from #{remote} (exit code #{status.exitstatus})") |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
601 |
end |
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
602 |
end |
127
664296ccdb4a
Improved tasks `workflow:out-staging` and `workflow:out-upstream`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
124
diff
changeset
|
603 |
else |
138 | 604 |
hg('outgoing', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev, &block) |
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
605 |
end |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
606 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
607 |
|
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
608 |
def push(remote = 'default', user: nil, pass: nil, rev: nil, bookmarks: []) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
609 |
hg('push', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev, bookmark: bookmarks) do |status, stdout, stderr| |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
610 |
STDOUT.puts stdout |
148
3abc438b6c59
Fixed slip in `hglib.rb` introduced in commit e665031cade7
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
138
diff
changeset
|
611 |
unless status.exitstatus == 0 or status.exitstatus == 1 |
124
d89325244d7c
hglib: show `hg` output when pushing to remote repositories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
120
diff
changeset
|
612 |
STDERR.puts stderr |
78
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
613 |
raise Exception.new("Failed to 'push' from #{remote} (exit code #{status.exitstatus})") |
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
614 |
end |
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
615 |
end |
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
616 |
end |
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
617 |
|
2d09a485772f
Push active bookmark (if any) when running task `workflow:push-staging` or...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
76
diff
changeset
|
618 |
|
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
619 |
# Create a shared clone in given directory, Return a new |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
620 |
# HG::Repository object on the shared clone |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
621 |
def share(dst, rev = nil) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
622 |
raise Exception.new("Destination file exists: #{dst}") if File.exist? dst |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
623 |
rev = log('.')[0] if rev.nil? |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
624 |
raise Exception.new("Revision #{rev} does not exist") unless has_revision? rev |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
625 |
mkdir_p File.dirname(dst) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
626 |
HG::hg('share', path, dst, config: 'extensions.share=', noupdate: true, bookmarks: false) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
627 |
share = Repository.new(dst) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
628 |
share.update(rev) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
629 |
share |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
630 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
631 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
632 |
# Updates the repository's working copy to given |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
633 |
# revision if given. If not, update to most-recent |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
634 |
# head, as plain |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
635 |
# |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
636 |
# hg update |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
637 |
# |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
638 |
# would do. |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
639 |
def update(rev = nil) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
640 |
if rev |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
641 |
raise Exception.new("Revision #{rev} does not exist") unless has_revision? rev |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
642 |
hg('update', rev: rev) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
643 |
else |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
644 |
hg('update') |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
645 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
646 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
647 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
648 |
# Merge given revision. Return true, if the merge was |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
649 |
# successful, false otherwise |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
650 |
def merge(rev) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
651 |
raise Exception.new("Revision #{rev} does not exist") unless has_revision? rev |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
652 |
hg('merge', rev) {|status| return status.success?} |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
653 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
654 |
|
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
655 |
def commit(message, user='') |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
656 |
user = @config['ui']['username'] unless @config['ui'].has_key? 'username' |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
657 |
hg('commit', message: message, user: user) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
658 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
659 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
660 |
def has_revision?(rev) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
661 |
revs = log(rev) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
662 |
revs.size > 0 |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
663 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
664 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
665 |
# Lookup a repository in given `directory`. If found, |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
666 |
# return it as instance of HG::Repository. If not, |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
667 |
# `nil` is returned. |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
668 |
def self.lookup(directory) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
669 |
return nil unless File.exist?(directory) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
670 |
repo_dir = directory |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
671 |
until repo_dir.nil? |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
672 |
return Repository.new(repo_dir) if HG::repository? repo_dir |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
673 |
repo_dir_parent = File.dirname(repo_dir) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
674 |
repo_dir_parent == repo_dir ? (repo_dir = nil) : (repo_dir = repo_dir_parent) |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
675 |
end |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
676 |
end |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
677 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
678 |
# Initializes and empty Mercurial repository in given `directory` |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
679 |
def self.init(directory) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
680 |
FileUtils.mkdir_p File.dirname(directory) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
681 |
HG::hg("init", directory) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
682 |
return Repository.new(directory) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
683 |
end |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
684 |
end # class Repository |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
685 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
686 |
# Return `true` if given `directory` is a root of mercurial |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
687 |
# repository, `false` otherwise. |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
688 |
def self.repository?(directory) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
689 |
return File.directory? File.join(directory, '.hg') |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
690 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
691 |
|
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
692 |
# Enumerate all repositories in given `directory` |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
693 |
def self.forest(directory, &block) |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
694 |
yield Repository.new(directory) if repository? directory |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
695 |
Dir.foreach(directory) do |x| |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
696 |
path = File.join(directory, x) |
137
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
697 |
if File.directory? path |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
698 |
if x == '.' or x == '..' or x == '.svn' or x == '.git' |
e665031cade7
Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents:
124
diff
changeset
|
699 |
next |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
700 |
elsif File.directory?(path) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
701 |
forest(path, &block) |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
702 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
703 |
end |
307
0531e67049d6
Rakefiles, CI: use `-o "StrictHostKeyChecking off"` when cloning / updating non-interactively
Jan Vrany <jan.vrany@labware.com>
parents:
302
diff
changeset
|
704 |
end |
66
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
705 |
end |
8d2d5dfe94d0
Refactored SCM support to use `hglib.rb` for performing Mercurial related tasks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
706 |
end # module HG |