winci-updater 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/History.txt +4 -0
  4. data/README.txt +90 -0
  5. data/Rakefile +7 -0
  6. data/features/development.feature +13 -0
  7. data/features/fixtures/files.git/HEAD +1 -0
  8. data/features/fixtures/files.git/config +7 -0
  9. data/features/fixtures/files.git/description +1 -0
  10. data/features/fixtures/files.git/hooks/applypatch-msg.sample +15 -0
  11. data/features/fixtures/files.git/hooks/commit-msg.sample +24 -0
  12. data/features/fixtures/files.git/hooks/post-commit.sample +8 -0
  13. data/features/fixtures/files.git/hooks/post-receive.sample +15 -0
  14. data/features/fixtures/files.git/hooks/post-update.sample +8 -0
  15. data/features/fixtures/files.git/hooks/pre-applypatch.sample +14 -0
  16. data/features/fixtures/files.git/hooks/pre-commit.sample +46 -0
  17. data/features/fixtures/files.git/hooks/pre-rebase.sample +169 -0
  18. data/features/fixtures/files.git/hooks/prepare-commit-msg.sample +36 -0
  19. data/features/fixtures/files.git/hooks/update.sample +128 -0
  20. data/features/fixtures/files.git/info/exclude +6 -0
  21. data/features/fixtures/files.git/objects/03/6fa7341563be59c8a77d97cb9491fa5cf45ceb +0 -0
  22. data/features/fixtures/files.git/objects/05/0a491267bf39675b8299b4a58bf0969b042074 +0 -0
  23. data/features/fixtures/files.git/objects/05/79c80f1bded5c888e4c5d0db0a620a9d862d43 +1 -0
  24. data/features/fixtures/files.git/objects/07/51c79876ff4eb8815818b9272343e3c7e33dea +0 -0
  25. data/features/fixtures/files.git/objects/0f/c94ca3dd1c6b88de8a3cf14f4dcceed8e09660 +0 -0
  26. data/features/fixtures/files.git/objects/11/90f934e40b4f046fcf85ea78db9fee8093abec +0 -0
  27. data/features/fixtures/files.git/objects/15/4cedd3733da97c11bdb7a117d1fae8b518bf34 +1 -0
  28. data/features/fixtures/files.git/objects/1f/71c1a207e09add411a5cecf69c10f55445b469 +0 -0
  29. data/features/fixtures/files.git/objects/20/b002ac4d646c229034cef829ff18624c977eb5 +0 -0
  30. data/features/fixtures/files.git/objects/21/a215f731df78dbd19f996206d7f767eee1b693 +0 -0
  31. data/features/fixtures/files.git/objects/23/9285087a6b72507556d4d3cc112c5fd31d53e0 +0 -0
  32. data/features/fixtures/files.git/objects/2b/9535c8e56553adb9aebb20ad1912e931716150 +0 -0
  33. data/features/fixtures/files.git/objects/2c/4581b957e00fabb337d4721ac5f2e2926c3789 +0 -0
  34. data/features/fixtures/files.git/objects/2c/a3daa8b8f25df70098f4a70841ab6388efa359 +0 -0
  35. data/features/fixtures/files.git/objects/2e/61d627945bcd38b8f9ddf859a74c2b2d02b7b2 +0 -0
  36. data/features/fixtures/files.git/objects/33/cc6691aba73113aa445e3f84a3366f4e98e3e0 +2 -0
  37. data/features/fixtures/files.git/objects/37/cc011ba9639bd5061d6f7b1a3a5dce82cd1f71 +0 -0
  38. data/features/fixtures/files.git/objects/3b/14857a8e7cb009f90cfcd066043031a282db00 +0 -0
  39. data/features/fixtures/files.git/objects/3b/369d6d123b120b39aa8948454bcc37253b5959 +0 -0
  40. data/features/fixtures/files.git/objects/44/a6ee1a915804490c0ad5dffb5ea23e5aa5b812 +0 -0
  41. data/features/fixtures/files.git/objects/69/1ed3b65603a0d0dabfb66720e7163664be78f5 +0 -0
  42. data/features/fixtures/files.git/objects/6a/9904979668a9990f0cf02351422a7236667d47 +2 -0
  43. data/features/fixtures/files.git/objects/6a/b5d1f20357490f4c88e43933c369ec7c70a5c2 +0 -0
  44. data/features/fixtures/files.git/objects/71/eb640bd5dc79c14a3526aef009579548ec98c8 +0 -0
  45. data/features/fixtures/files.git/objects/72/cb06bbb46845dac41abe5c43850b8776713462 +0 -0
  46. data/features/fixtures/files.git/objects/89/e4b6c7d553678c64ce2ca045e9fc9a4361d690 +0 -0
  47. data/features/fixtures/files.git/objects/8d/e9e3b959ac8c2dffe3b7515be1d4956b8baf49 +0 -0
  48. data/features/fixtures/files.git/objects/92/e2e7031fb99e9167e322894d63fc8e0507c2c4 +2 -0
  49. data/features/fixtures/files.git/objects/94/87e688ef97be0548a786bda7950d037c20bbbb +0 -0
  50. data/features/fixtures/files.git/objects/a9/10b1bd4a24ad1b2d62605c857f84c79013b977 +2 -0
  51. data/features/fixtures/files.git/objects/ac/e379a6acc4ab141c97572504a5b9d93f0ddcb1 +0 -0
  52. data/features/fixtures/files.git/objects/b7/5117ab9cc4c4216d06c018bb020df581c2c30d +0 -0
  53. data/features/fixtures/files.git/objects/c9/ca14ae5fd726fe7513f14d51889e48f5adbc3f +0 -0
  54. data/features/fixtures/files.git/objects/d0/925b51ab3408d6fef51d5a40d39ae093fb6540 +2 -0
  55. data/features/fixtures/files.git/objects/da/da52d59d000dacf2495252a374d4cbc3868789 +0 -0
  56. data/features/fixtures/files.git/objects/df/d10fbf3f8b159f9385988b7deb386604598afc +0 -0
  57. data/features/fixtures/files.git/objects/fd/b794eac9712eab2c12866319af6767b8b9e556 +0 -0
  58. data/features/fixtures/files.git/refs/heads/master +1 -0
  59. data/features/step_definitions/common_steps.rb +183 -0
  60. data/features/step_definitions/jenkins_steps.rb +113 -0
  61. data/features/support/common.rb +37 -0
  62. data/features/support/env.rb +20 -0
  63. data/features/support/matchers.rb +9 -0
  64. data/features/works_with_continuous_delivery.feature +18 -0
  65. data/lib/winci-updater.rb +6 -0
  66. data/lib/winci-updater/const.rb +57 -0
  67. data/lib/winci-updater/core_ext/string.rb +9 -0
  68. data/lib/winci-updater/git.rb +134 -0
  69. data/lib/winci-updater/git_ext/base.rb +30 -0
  70. data/lib/winci-updater/git_ext/git.rb +15 -0
  71. data/lib/winci-updater/git_ext/lib.rb +120 -0
  72. data/lib/winci-updater/gui.rb +47 -0
  73. data/lib/winci-updater/logger.rb +54 -0
  74. data/lib/winci-updater/version.rb +5 -0
  75. data/spec/fixtures/files.git/HEAD +1 -0
  76. data/spec/fixtures/files.git/config +10 -0
  77. data/spec/fixtures/files.git/description +1 -0
  78. data/spec/fixtures/files.git/hooks/applypatch-msg.sample +15 -0
  79. data/spec/fixtures/files.git/hooks/commit-msg.sample +24 -0
  80. data/spec/fixtures/files.git/hooks/post-commit.sample +8 -0
  81. data/spec/fixtures/files.git/hooks/post-receive.sample +15 -0
  82. data/spec/fixtures/files.git/hooks/post-update.sample +8 -0
  83. data/spec/fixtures/files.git/hooks/pre-applypatch.sample +14 -0
  84. data/spec/fixtures/files.git/hooks/pre-commit.sample +46 -0
  85. data/spec/fixtures/files.git/hooks/pre-rebase.sample +169 -0
  86. data/spec/fixtures/files.git/hooks/prepare-commit-msg.sample +36 -0
  87. data/spec/fixtures/files.git/hooks/update.sample +128 -0
  88. data/spec/fixtures/files.git/info/exclude +6 -0
  89. data/spec/fixtures/files.git/objects/0d/6b60095e8ee0e285b63964392a346f1a484c76 +0 -0
  90. data/spec/fixtures/files.git/objects/92/2951e4b5e9b3539344ac83aed95005ddc64c7e +0 -0
  91. data/spec/fixtures/files.git/objects/c3/c88adeec62fc2b3cc3494f1a0a34bfb66f2fbe +2 -0
  92. data/spec/fixtures/files.git/refs/heads/master +1 -0
  93. data/spec/fixtures/files_changed.git/HEAD +1 -0
  94. data/spec/fixtures/files_changed.git/config +10 -0
  95. data/spec/fixtures/files_changed.git/description +1 -0
  96. data/spec/fixtures/files_changed.git/hooks/applypatch-msg.sample +15 -0
  97. data/spec/fixtures/files_changed.git/hooks/commit-msg.sample +24 -0
  98. data/spec/fixtures/files_changed.git/hooks/post-commit.sample +8 -0
  99. data/spec/fixtures/files_changed.git/hooks/post-receive.sample +15 -0
  100. data/spec/fixtures/files_changed.git/hooks/post-update.sample +8 -0
  101. data/spec/fixtures/files_changed.git/hooks/pre-applypatch.sample +14 -0
  102. data/spec/fixtures/files_changed.git/hooks/pre-commit.sample +46 -0
  103. data/spec/fixtures/files_changed.git/hooks/pre-rebase.sample +169 -0
  104. data/spec/fixtures/files_changed.git/hooks/prepare-commit-msg.sample +36 -0
  105. data/spec/fixtures/files_changed.git/hooks/update.sample +128 -0
  106. data/spec/fixtures/files_changed.git/info/exclude +6 -0
  107. data/spec/fixtures/files_changed.git/objects/0d/6b60095e8ee0e285b63964392a346f1a484c76 +0 -0
  108. data/spec/fixtures/files_changed.git/objects/2f/a2b556695fb8a023d191859153686e2cb04545 +0 -0
  109. data/spec/fixtures/files_changed.git/objects/49/9050cfcb971c6c684a5f2a2d6638406d8f0865 +0 -0
  110. data/spec/fixtures/files_changed.git/objects/80/e133724c1eb772ee56359c5e71fd200bfb20cc +0 -0
  111. data/spec/fixtures/files_changed.git/objects/92/2951e4b5e9b3539344ac83aed95005ddc64c7e +0 -0
  112. data/spec/fixtures/files_changed.git/objects/c3/c88adeec62fc2b3cc3494f1a0a34bfb66f2fbe +2 -0
  113. data/spec/fixtures/files_changed.git/refs/heads/master +1 -0
  114. data/spec/fixtures/key +27 -0
  115. data/spec/git_spec.rb +49 -0
  116. data/spec/spec_helper.rb +9 -0
  117. data/tasks/cucumber.rake +23 -0
  118. data/tasks/rspec.rake +9 -0
  119. data/winci-updater.gemspec +28 -0
  120. metadata +280 -0
@@ -0,0 +1,113 @@
1
+ Given /^I have WinCI\-server installed in "([^\"]*)"$/ do |winci_server_path|
2
+ @winci_server_path = winci_server_path
3
+
4
+ # below file gets created after running winci-server/install.bat
5
+ File.exists?(File.join(winci_server_path, "ruby/bin/ruby.exe")).should == true
6
+ end
7
+
8
+ When /^I have a Jenkins server running$/ do
9
+ require 'socket'
10
+ require 'net/http'
11
+ begin
12
+ print "."; $stdout.flush
13
+ Net::HTTP.start("localhost", "3010") { |http| http.get('/') }
14
+ rescue Exception => e
15
+ system "rake --rakefile #{File.join(@winci_server_path, "restart_jenkins.rake")} restart_jenkins"
16
+ ensure
17
+ end
18
+ end
19
+
20
+ When /^there exist job named "([^\"]*)" that pushes successful build to "([^\"]*)" repo$/ do |project_name, production_repo|
21
+ @project_name = project_name
22
+
23
+ FileUtils.rm_rf File.expand_path('var/')
24
+ FileUtils.mkdir File.expand_path('var/')
25
+ FileUtils.cp_r(File.expand_path('features/fixtures/files.git'), File.expand_path('var/'))
26
+
27
+ # TODO move to separate step
28
+ # prepare production repo
29
+ FileUtils.mkdir File.expand_path(File.dirname(production_repo))
30
+ FileUtils.cp_r(File.expand_path('features/fixtures/files.git'), File.expand_path(production_repo))
31
+
32
+ # create job config
33
+ cfg = Jenkins::JobConfigBuilder.new(:ruby) do |c|
34
+ c.scm = File.expand_path('var/files.git') #"C:/repos/#{@project_name}.git"
35
+ c.steps = [
36
+ # below makes sense when your Rakefile run rspec/cucumber by default
37
+ [:build_bat_step, "bundle exec rake"],
38
+ # this will send current code to production repo only after rspec/cucumber passed
39
+ [:build_bat_step, "git push #{File.expand_path(production_repo)} HEAD:master"]
40
+ ]
41
+ end
42
+
43
+ job = WinCI::Job.new @project_name, cfg
44
+
45
+
46
+ print "waiting for at most 30 seconds for the server to create the job"
47
+ tries = 0
48
+ begin
49
+ print "."; $stdout.flush
50
+ tries += 1
51
+
52
+ # by default creates job on localhost:3010
53
+ @job_creation_res = job.create
54
+ raise if not @job_creation_res =~ /.*project created on jenkins.*/
55
+
56
+ sleep(10)
57
+ puts ""
58
+ rescue Exception => e
59
+ if tries <= 3
60
+ sleep 2
61
+ retry
62
+ end
63
+ ensure
64
+ end
65
+
66
+ @job_creation_res.should =~ /.*project created on jenkins.*/
67
+ end
68
+
69
+ When /^the job has at least one successful build$/ do
70
+ job = WinCI::Job.new @project_name
71
+ sha = nil
72
+ begin
73
+ sha = job.last_successful_build_sha
74
+ rescue
75
+ Jenkins::Api.build_job(@project_name)
76
+ puts "waiting 40 seconds for the server to build the job"
77
+ sleep 40
78
+ sha = job.last_successful_build_sha
79
+ end
80
+ sha.should_not be_empty
81
+ end
82
+
83
+ When /^I run updater with "([^\"]*)" in config$/ do |production_repo|
84
+ File.open('var/_config.yaml', 'w') do |f|
85
+ f.puts ":SCMs:"
86
+ f.puts "- \"#{File.expand_path(production_repo)}\""
87
+ end
88
+
89
+ @git = WinCI::Updater::Git.new "var/_config.yaml"
90
+ @git.setup_ssh_key "spec/fixtures/key"
91
+
92
+ @updater_res = @git.provide File.expand_path('var/'), 'files_cloned', false
93
+ end
94
+
95
+ When /^I run updater with "([^\"]*)" in config and target dir "([^\"]*)" as parameter$/ do |production_repo, target_dir|
96
+ File.open(File.expand_path('var/_config.yaml'), 'w') do |f|
97
+ f.puts ":SCMs:"
98
+ f.puts "- \"#{File.expand_path(production_repo)}\""
99
+ end
100
+
101
+ @git = WinCI::Updater::Git.new "var/_config.yaml"
102
+ @git.setup_ssh_key "spec/fixtures/key"
103
+
104
+ @updater_res = @git.provide File.expand_path('var/'), 'files_cloned', false
105
+ end
106
+
107
+ Then /^I should see this$/ do |text|
108
+ @updater_res.strip.upcase.should contain(text.strip.upcase)
109
+ end
110
+
111
+ When /^directory named "([^\"]*)" is created$/ do |arg1|
112
+ File.exists?(File.expand_path('var/files_cloned/.git/')).should be_true
113
+ end
@@ -0,0 +1,37 @@
1
+ module CommonHelpers
2
+ def get_command_output
3
+ strip_color_codes(File.read(@stdout)).chomp
4
+ end
5
+
6
+ def strip_color_codes(text)
7
+ text.gsub(/\e\[\d+m/, '')
8
+ end
9
+
10
+ def in_tmp_folder(&block)
11
+ FileUtils.chdir(@tmp_root, &block)
12
+ end
13
+
14
+ def in_project_folder(&block)
15
+ project_folder = @active_project_folder || @tmp_root
16
+ FileUtils.chdir(project_folder, &block)
17
+ end
18
+
19
+ def in_home_folder(&block)
20
+ FileUtils.chdir(@home_path, &block)
21
+ end
22
+
23
+ def force_local_lib_override(project_name = @project_name)
24
+ rakefile = File.read(File.join(project_name, 'Rakefile'))
25
+ File.open(File.join(project_name, 'Rakefile'), "w+") do |f|
26
+ f << "$:.unshift('#{@lib_path}')\n"
27
+ f << rakefile
28
+ end
29
+ end
30
+
31
+ def setup_active_project_folder project_name
32
+ @active_project_folder = File.join(@tmp_root, project_name)
33
+ @project_name = project_name
34
+ end
35
+ end
36
+
37
+ World(CommonHelpers)
@@ -0,0 +1,20 @@
1
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + "/../../lib"))
2
+ require 'winci-updater.rb'
3
+ require 'bundler/setup'
4
+ require 'jenkins'
5
+ require 'winci'
6
+
7
+ Before do
8
+ @tmp_root = File.dirname(__FILE__) + "/../../tmp"
9
+ @home_path = File.expand_path(File.join(@tmp_root, "home"))
10
+ @lib_path = File.expand_path(File.dirname(__FILE__) + "/../../lib")
11
+ FileUtils.rm_rf @tmp_root
12
+ FileUtils.mkdir_p @home_path
13
+ ENV['HOME'] = @home_path
14
+ ENV['CUCUMBER_RUNNING'] = 'oooh yes'
15
+ end
16
+
17
+ After do
18
+ ENV.delete('JENKINS_HOST')
19
+ ENV.delete('JENKINS_PORT')
20
+ end
@@ -0,0 +1,9 @@
1
+ module Matchers
2
+ RSpec::Matchers.define :contain do |expected_text|
3
+ match do |text|
4
+ text.index expected_text
5
+ end
6
+ end
7
+ end
8
+
9
+ World(Matchers)
@@ -0,0 +1,18 @@
1
+ Feature: Works with WinCI continuous delivery process
2
+ In order to enhance provisioning in continuous delivery process
3
+ As a project developer
4
+ I want to fully integrate updater with WinCI continuous delivery process
5
+
6
+ Background:
7
+ Given I have WinCI-server installed in "C:/winci-server"
8
+ And I have a Jenkins server running
9
+ And there exist job named "files" that pushes successful build to "var/production/files.git" repo
10
+ And the job has at least one successful build
11
+
12
+ Scenario: Download last successful build
13
+ When I run updater with "var/production/files.git" in config and target dir "files_cloned" as parameter
14
+ Then I should see this
15
+ """
16
+ Update successful!
17
+ """
18
+ And directory named "files_cloned" is created
@@ -0,0 +1,6 @@
1
+ module WinCI
2
+ module Updater
3
+ require 'winci-updater/version'
4
+ require 'winci-updater/git'
5
+ end
6
+ end
@@ -0,0 +1,57 @@
1
+ require "logger"
2
+
3
+ module WinCI
4
+ module Updater
5
+
6
+ UPDATER_WINDOW_TITLE = 'Updater'
7
+
8
+ LOG_FILE = 'git_responses.log' # file used to log git command responses
9
+ LOGGER_LEVEL = Logger::DEBUG # possible values: Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR, Logger::FATAL
10
+
11
+ TOLERATED_STASH_MESSAGES = [\
12
+ 'No local changes to save', \
13
+ 'Saved working directory .*HEAD is now at .*',\
14
+ ]
15
+
16
+ # actually they are not messages from 'pull' but from 'merge' which is part of 'pull' command
17
+ TOLERATED_PULL_MESSAGES = [\
18
+ 'Already up-to-date.', \
19
+ 'Updating .*', \
20
+ 'Merge made by recursive..*',\
21
+ ]
22
+
23
+ TOLERATED_CLONE_MESSAGES = [\
24
+ 'Already up-to-date.',\
25
+ ]
26
+
27
+ # button constants
28
+ MB_OK = 0x00000000
29
+ MB_OKCANCEL = 0x00000001
30
+ MB_ABORTRETRYIGNORE = 0x00000002
31
+ MB_YESNOCANCEL = 0x00000003
32
+ MB_YESNO = 0x00000004
33
+ MB_RETRYCANCEL = 0x00000005
34
+ MB_SETFOREGROUND = 0x00010000
35
+ MB_TOPMOST = 0x00040000
36
+ MB_ICONEXCLAMATION = 0x00000030
37
+ MB_CANCELTRYCONTINUE = 0x00000006
38
+ MB_ICONHAND = 0x00000010
39
+ MB_ICONQUESTION = 0x00000020
40
+ MB_ICONASTERISK = 0x00000040
41
+ MB_USERICON = 0x00000080
42
+ MB_ICONWARNING = MB_ICONEXCLAMATION
43
+ MB_ICONERROR = MB_ICONHAND
44
+ MB_ICONINFORMATION = MB_ICONASTERISK
45
+ MB_ICONSTOP = MB_ICONHAND
46
+
47
+ # return code constants
48
+ CLICKED_OK = 1
49
+ CLICKED_CANCEL = 2
50
+ CLICKED_ABORT = 3
51
+ CLICKED_RETRY = 4
52
+ CLICKED_IGNORE = 5
53
+ CLICKED_YES = 6
54
+ CLICKED_NO = 7
55
+
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ class String
2
+ def match_any?(arrayOfPatterns)
3
+ arrayOfPatterns.each do |pattern|
4
+ result = self.match(/#{pattern}/m)
5
+ return true if result
6
+ end
7
+ return false
8
+ end
9
+ end
@@ -0,0 +1,134 @@
1
+ require 'rubygems'
2
+ require 'dl'
3
+ require 'yaml'
4
+
5
+ require "optparse"
6
+ require "date"
7
+ require "pathname"
8
+ require "fileutils"
9
+ require "git"
10
+
11
+ require 'winci-updater/git_ext/git'
12
+ require 'winci-updater/git_ext/lib'
13
+ require 'winci-updater/git_ext/base'
14
+ require 'winci-updater/core_ext/string'
15
+ require 'winci-updater/const'
16
+ require 'winci-updater/logger'
17
+
18
+ module WinCI
19
+ module Updater
20
+ class Git
21
+ def initialize config_path="_config.yaml"
22
+ @config = YAML.load_file(config_path)
23
+
24
+ # create new log file periodically -- each month/week/day
25
+ $log = TLogger.new(LOG_FILE, 'monthly', STDOUT, true) # possible values: 'monthly', 'weekly', 'daily'
26
+ # limit the output
27
+ $log.level = LOGGER_LEVEL
28
+
29
+ $log.info("\r\n\r\n\r\nStarting script...\r\n\r\n")
30
+
31
+ ensure_git_available
32
+ end
33
+
34
+ def ensure_git_available
35
+ if File.exists?("../PortableGit/bin/git.exe")
36
+ git_dir = File.expand_path('../PortableGit/bin', File.dirname(__FILE__))
37
+ ENV['PATH'] = ENV['PATH'] + ';' + git_dir
38
+ else
39
+ # check if git.exe is on PATH
40
+ begin
41
+ `git status`
42
+ rescue
43
+ raise "Cannot find Git installation! Please reinstall using Git-1.7.0.2-preview20100309.exe or simmilar file!\r\n" +
44
+ "The file can be obtained from here: http://code.google.com/p/msysgit/downloads"
45
+ end
46
+ end
47
+ end
48
+
49
+ def setup_ssh_key key_path="key"
50
+ res = ::Git.setup_ssh_key key_path
51
+ if not res
52
+ res = 'Error while creating ssh-agent or adding ssh key!'
53
+ end
54
+ raise res if not res['Identity added']
55
+ @ssh_agent_enabled = true
56
+ end
57
+
58
+ def provide_scm scm, localPath
59
+ if File.directory?(localPath)
60
+ $log.info("\r\nUpdating '#{localPath}' repository")
61
+ g = ::Git.open(localPath, :log => $log)
62
+ # before overwriting with pull, here we do backup of any user made changes to files in the repo
63
+ res = g.stash(:save => true, :message => 'Changes made by user')
64
+ if not res.match_any? TOLERATED_STASH_MESSAGES then
65
+ @not_tolerated_messages << res
66
+ return
67
+ end
68
+
69
+ # update the repo
70
+ # Note: this command can return 'Already up to date' message
71
+ res = g.pull("origin", "origin/master")
72
+ if not res.match_any? TOLERATED_PULL_MESSAGES then
73
+ @not_tolerated_messages << res
74
+ return
75
+ end
76
+ else # we clone it if it doesnt exist yet
77
+ $log.info("\r\nCloning '#{localPath}' repository")
78
+ opts = {}
79
+ opts[:depth] = 1
80
+ g = ::Git.clone(scm, localPath, opts)
81
+ end
82
+ end
83
+
84
+ def provide target_dir = "./", target_repo_name = nil, handle_failure = true
85
+ @not_tolerated_messages = []
86
+
87
+ begin
88
+
89
+ @config[:SCMs].each do |scm|
90
+ begin
91
+ target_repo_name = File.basename(scm, '.*') if not target_repo_name
92
+ provide_scm(scm, File.join(target_dir, target_repo_name))
93
+ rescue ::Git::GitExecuteError => e
94
+ @not_tolerated_messages << e
95
+ end
96
+ end
97
+
98
+ msg = ''
99
+ buttons = MB_SETFOREGROUND | MB_OK
100
+ if @not_tolerated_messages.length > 0
101
+ msg = "Unknown message received while updating, please consult developement team.\r\n"+
102
+ "It is possible that the message means success.\r\n"+"DETAILS:\r\n" + @not_tolerated_messages.join("\r\n")
103
+ buttons = MB_ICONERROR | buttons
104
+ else
105
+ msg = "Update Successful!"
106
+ end
107
+
108
+ $log.info("\r\n\r\nSUMMARY:\r\n")
109
+ $log.info(msg)
110
+ if handle_failure
111
+ puts msg
112
+ message_box(msg, UPDATER_WINDOW_TITLE, buttons)
113
+ else
114
+ return msg
115
+ end
116
+
117
+ rescue => e
118
+ msg = e.message.gsub('uncaught throw ', '')
119
+ $log.error(msg)
120
+ if handle_failure
121
+ puts msg
122
+ message_box("Update Failed! #{msg}", UPDATER_WINDOW_TITLE, buttons=MB_OK | MB_SETFOREGROUND | MB_ICONERROR)
123
+ else
124
+ raise
125
+ end
126
+ ensure
127
+ ::Git.kill_ssh_agent if @ssh_agent_enabled
128
+ @ssh_agent_enabled = nil
129
+ end
130
+ end
131
+
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,30 @@
1
+ module Git
2
+
3
+ class Base
4
+
5
+ def self.setup_ssh_key(ssh_key_path)
6
+ Git::Lib.new.setup_ssh_key(ssh_key_path)
7
+ end
8
+
9
+ def self.kill_ssh_agent
10
+ Git::Lib.new.kill_ssh_agent
11
+ end
12
+
13
+ def show_head_names
14
+ self.lib.show_head_names
15
+ end
16
+
17
+ # cleans a git repository locally
18
+ def clean(opts = {})
19
+ # run git-clone
20
+ self.lib.clean(opts)
21
+ end
22
+
23
+ def stash(opts = {})
24
+ # run git-stash
25
+ self.lib.stash(opts)
26
+ end
27
+
28
+ end
29
+
30
+ end