rebuild 0.1.3 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 957706f22bd92740d0d8cd7848ea386b79f4b58f
4
- data.tar.gz: 50509f90336c574c79d48c884e4b26a721c4b206
3
+ metadata.gz: d5e6f743ea4800a0758acc8d4741e512a78705a4
4
+ data.tar.gz: 02212939decd5c08df98de2b53a649cb6a1a1eaa
5
5
  SHA512:
6
- metadata.gz: 0be07f9ed542d865d2ce7779d72a56989f2e90e21b0499ea166186cdc37f98412d94a795aac62d84abe0e90cb5dc528ad105bdaf005b9dfebcfe0ebc2df3a46e
7
- data.tar.gz: f350ad7dee2d1c10c0761034260a2051002eefce4a53b60a118c2e03f1e7d96e262a78afeb6bae33a704dde7efa23cfa35f171ff5b1089cf20afbabdf80a63bb
6
+ metadata.gz: dfe9c634f3d0b227998f55cdcf0a9b22a256a002eceb1b84b70d1d5054d6128faa07ce95b87896f3b2647cf22cd115b7d0664ef789a077abff0084550f99dc54
7
+ data.tar.gz: 71ef170f0534e471efeae2337765a50cbd9f9ef9d812d970ae894d35cf0eae0a9ad280106c609ca7a207902c0f748a895a0fb1bcccb80da47af5349c80e311c6
@@ -14,36 +14,43 @@ module Rebuild
14
14
  end
15
15
 
16
16
  def fetch
17
- FileUtils.mkdir_p(user_path)
18
- clone_archive
17
+ if File.exists?(repo_path)
18
+ sync_repository
19
+ else
20
+ clone_repository
21
+ end
19
22
 
20
23
  repo_path
21
24
  end
22
25
 
23
26
  private
24
27
 
25
- def clone_archive
26
- if File.exists?(repo_path)
27
- puts "Directory already exists. Clone skipped."
28
- return
28
+ def clone_repository
29
+ FileUtils.mkdir_p(user_path)
30
+ `git clone #{github_repository} #{repo_path}`
31
+ end
32
+
33
+ def sync_repository
34
+ if dirty_repository?
35
+ puts 'Repository has unstaged changes. Sync skipped.'
36
+ else
37
+ run_with_repository('git pull origin master')
29
38
  end
39
+ end
30
40
 
31
- print "Cloning into #{repo_path}..."
32
- download_archive
33
- unzip_archive
34
- FileUtils.rm(archive_path)
35
- puts " done."
41
+ def dirty_repository?
42
+ run_with_repository('[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]')
36
43
  end
37
44
 
38
- def download_archive
39
- `curl -Ls -o #{archive_path} #{archive_url}`
45
+ def run_with_repository(script)
46
+ system(<<-EOS)
47
+ cd #{repo_path}
48
+ #{script}
49
+ EOS
40
50
  end
41
51
 
42
- def unzip_archive
43
- `unzip -o #{archive_path} -d #{user_path} > /dev/null`
44
- unzipped_path = File.join(user_path, "#{@repo}-#{@reference}")
45
- FileUtils.rm_rf(repo_path)
46
- FileUtils.mv(unzipped_path, repo_path)
52
+ def github_repository
53
+ "git@github.com:#{@user}/#{@repo}"
47
54
  end
48
55
 
49
56
  def repo_path
@@ -53,13 +60,5 @@ module Rebuild
53
60
  def user_path
54
61
  File.join(FETCH_DIRECTORY, @user)
55
62
  end
56
-
57
- def archive_path
58
- File.join(user_path, "#{@repo}.zip")
59
- end
60
-
61
- def archive_url
62
- "https://github.com/#{@user}/#{@repo}/archive/#{@reference}.zip"
63
- end
64
63
  end
65
64
  end
@@ -1,3 +1,3 @@
1
1
  module Rebuild
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rebuild
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun