au 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e518fc6352a564efdca3da72b466c5d9b77eb2c735305e1d584383206088671
4
- data.tar.gz: e0ff19709aa951e5f5e02f7902bafcfe20310dcd18e28b7587cf72e610796e91
3
+ metadata.gz: 747b7a38e077a90fcae85a25a41debea6a9c66f6e8c66605e4d298268bdd21cd
4
+ data.tar.gz: 82a01914628d92827535d2d587681d260e73369133366c752ce4985895e8dd7d
5
5
  SHA512:
6
- metadata.gz: 68e8f95de2d98f317389027fb69433fbbdd3fd4cf5043ddb2ddb0ce910e43f6c15adfa3adc809073ea44f2793608200b4f952ad8021eb106e4ec743fa69c637c
7
- data.tar.gz: 92d5ac6ef1685e887c2e0daf0498068bdf448418429c97fb6f81739e759a41d02bd28beadc9fbf82c91c528489498dcfe8aad65988cade54b34b5192bbc001cc
6
+ metadata.gz: b82d4e806d17cf8c6429967461e437612a7927931a1db214a387e870ade5458e6f2e4e58f4a9f41b0989b9e725e0b78247a5a7c96f2dc6e1109173436e6a978b
7
+ data.tar.gz: 2917e2d460448b99a06308e2e1daed33a89a03ffc5bc3828611e1cea0ecaeba0eb9d0b8e4f325326649537ae1b079bd15b007bd1725444a3851bacb17c4322eb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- au (0.1.0)
4
+ au (0.1.1)
5
5
  colorize
6
6
  thor
7
7
 
data/README.md CHANGED
@@ -15,10 +15,21 @@ literal translation of which can be loosely interpreted as 'wow' (as in Jay Chou
15
15
 
16
16
  ## Installation
17
17
 
18
+ For your convenience (and sanity), this library is released on https://rubygems.org/ at https://rubygems.org/gems/au.
19
+
20
+ To install
21
+
18
22
  $ gem install au
19
23
 
24
+
25
+ **This project ONLY supports Ruby 2.5.0 and above**. Due to the Integer class changes in Ruby 2.5.0,
26
+ **any older version will error**. If your system comes with an older version, please either
27
+ update your Ruby installation or use [rbenv](https://github.com/rbenv/rbenv). You may need to use `sudo`. Additionally, if you are on an outdated Ruby installation, please make sure your load path is updated for Ruby executable.
28
+
20
29
  ## Usage
21
30
 
31
+ A simple get-started [tutorial video](https://www.useloom.com/share/6372bf5d22b8482299f3c788559d4173).
32
+
22
33
  ```
23
34
  Commands:
24
35
  au cat COMMIT_ID PATH
@@ -73,21 +84,27 @@ Commands:
73
84
  # Remove one or more files from the staging area.
74
85
  ```
75
86
 
76
- ## Development
87
+ ## Development Build
88
+
89
+ This project uses bundler to manage production and development dependencies (see more in 'depenedencies' section).
90
+
91
+ Again, this project requires Ruby 2.5.0 or higher.
77
92
 
78
93
  `gem install bundler` to install bundler
79
94
 
80
95
  `bundle install` to install all dependencies
81
96
 
82
- `bundle exec rspec` to run rspec tests
97
+ Unit specs are written in RSpec. Use `bundle exec rspec` to run all unit specs.
98
+
99
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
100
 
84
- -----
101
+ ## Dependencies
85
102
 
86
- `bundle exec au init` to init
103
+ This project has the following produciton dependencies:
87
104
 
88
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
105
+ * Thor - We use thor to save time with the chores in handling cmd flags and documentation.
106
+ * Colorize - We use colorize to give our cmd output colors.
89
107
 
90
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
91
108
 
92
109
  ## Contributing
93
110
 
data/bin/au CHANGED
@@ -20,7 +20,7 @@ module Au
20
20
  puts 'Welcome to AU. Your project is now tracked.'
21
21
  end
22
22
 
23
- desc "clone remote PATH and target PATH", "Copy an existing repo"
23
+ desc "clone remote REMOTE_PATH", "Copy an existing repo"
24
24
  def clone(remote_repo_root, target_repo_root = nil)
25
25
  # default target path is the same with rename's name in current working directory
26
26
  target_repo_root = File.join(Dir.pwd, File.basename(remote_repo_root)) if target_repo_root.nil?
@@ -89,7 +89,7 @@ module Au
89
89
  Repository.instance.heads
90
90
  end
91
91
 
92
- desc "diff PATH", "Display between tracked version and current version"
92
+ desc "diff PATH", "Diff between tracked version and current version"
93
93
  def diff(file_path)
94
94
  diff = Repository.diff(file_path)
95
95
  if diff.present?
@@ -181,23 +181,6 @@ module Au
181
181
  end
182
182
  end
183
183
 
184
- def self.lowest_common_ancestor(parent_commit_1, parent_commit_2)
185
- # keys are commit id, values are Array of number of hops
186
- all_ancestors_of_parent_1 = self.gen_ancestor_set(parent_commit_1, Set.new, skip_first=true)
187
- all_ancestors_of_parent_2 = self.gen_ancestor_set(parent_commit_2, Set.new, skip_first=true)
188
-
189
- common_ancestors = all_ancestors_of_parent_1 & all_ancestors_of_parent_2
190
- raise 'no common ancestors' if common_ancestors.size.zero?
191
-
192
- while common_ancestors.size != 1
193
- picked_ancestor = common_ancestors.first
194
- ancestors_to_be_removed_set = gen_ancestor_set(picked_ancestor, Set.new, skip_first=true)
195
- common_ancestors -= ancestors_to_be_removed_set
196
- end
197
-
198
- common_ancestors.first
199
- end
200
-
201
184
  # returns a tempfile with the content of the document at the recorded diff of commit.
202
185
  def cat(file_path)
203
186
  diff_id = doc_diff_ids[file_path]
@@ -255,5 +238,23 @@ module Au
255
238
  end
256
239
  commit_id_set
257
240
  end
241
+
242
+ def self.lowest_common_ancestor(parent_commit_1, parent_commit_2)
243
+ # keys are commit id, values are Array of number of hops
244
+ all_ancestors_of_parent_1 = self.gen_ancestor_set(parent_commit_1, Set.new, skip_first=true)
245
+ all_ancestors_of_parent_2 = self.gen_ancestor_set(parent_commit_2, Set.new, skip_first=true)
246
+
247
+ common_ancestors = all_ancestors_of_parent_1 & all_ancestors_of_parent_2
248
+ raise 'no common ancestors' if common_ancestors.size.zero?
249
+
250
+ while common_ancestors.size != 1
251
+ picked_ancestor = common_ancestors.first
252
+ ancestors_to_be_removed_set = gen_ancestor_set(picked_ancestor, Set.new, skip_first=true)
253
+ common_ancestors -= ancestors_to_be_removed_set
254
+ end
255
+
256
+ common_ancestors.first
257
+ end
258
+
258
259
  end
259
260
  end
@@ -2,7 +2,6 @@ require 'pstore'
2
2
  require 'tempfile'
3
3
  require 'digest/md5'
4
4
  require 'fileutils'
5
- require_relative '../models/diff'
6
5
 
7
6
  module Au
8
7
  class Document
@@ -97,7 +96,8 @@ module Au
97
96
  end
98
97
 
99
98
  def abs_path
100
- File.join(Repository.root, path)
99
+ paths = [Repository.root, path].compact
100
+ File.join(*paths)
101
101
  end
102
102
 
103
103
  end
@@ -26,10 +26,14 @@ module Au
26
26
 
27
27
  def self.instance(path = nil, create = false)
28
28
  return @single_instance unless @single_instance.nil?
29
- @single_instance = new(path, create)
29
+ begin
30
+ @single_instance = new(path, create)
31
+ rescue
32
+ Kernel.abort("Fetal error: Repository not found. ")
33
+ end
30
34
  end
31
35
 
32
- def initialize(path, create = false, remote_path = nil)
36
+ def initialize(path, create = false)
33
37
  if path.nil?
34
38
  working_dir = Dir.pwd
35
39
  # little bit different with mercurial 0.1
@@ -106,19 +110,19 @@ module Au
106
110
  raise "Error: Root commits do not match."
107
111
  end
108
112
 
109
- # Find commits that only exist locally
113
+ # Find commits that only exist on remote repo
110
114
  commit_id_to_add_list = remote_commit_list.reject{|x| local_commit_list.include?(x)}
111
115
  commits_to_add = {}
112
116
  remote_commit_db.transaction(true) do
113
117
  commit_id_to_add_list.each{|commit_id| commits_to_add[commit_id] = remote_commit_db[commit_id]}
114
118
  end
115
119
 
116
- # Write those commits to remote commit db
120
+ # Write those commits to local commit db
117
121
  local_commit_db.transaction do
118
122
  commits_to_add.each{|commit_id, data| local_commit_db[commit_id] = data}
119
123
  end
120
124
 
121
- # Find documents and their diff_id in those commits that only existed locally
125
+ # Find documents and their diff_id in those commits that only existed remotely
122
126
  remote_diff_id_to_add_list = {}
123
127
  commits_to_add.each do |commit|
124
128
  commit[:doc_diff_ids].each do |doc_path, diff_id|
@@ -41,6 +41,7 @@ module Au
41
41
  relative_paths
42
42
  end
43
43
 
44
+ # private
44
45
  def self.filter_stageable(last_commit, relative_paths)
45
46
  tracked_docs_md5 = last_commit&.tracked_docs_md5 || {}
46
47
  relative_paths.reject do |relative_path|
@@ -65,6 +66,16 @@ module Au
65
66
  end
66
67
 
67
68
  def self.unstage(file_paths)
69
+ file_paths = file_paths.each_with_object([]) do |staged_path, accum|
70
+ if File.directory?(staged_path)
71
+ Dir.glob('**/*', base: staged_path) do |sub_path|
72
+ accum << (File.join(staged_path, sub_path)) unless File.directory?(sub_path)
73
+ end
74
+ else
75
+ accum << staged_path
76
+ end
77
+ end
78
+
68
79
  stage_db.transaction do
69
80
  file_paths.each do |file_path|
70
81
  stage_db.delete(file_path)
@@ -73,7 +84,8 @@ module Au
73
84
  end
74
85
 
75
86
  def self.abs_path(relative_path)
76
- File.join(Repository.root, relative_path)
87
+ paths = [Repository.root, relative_path].compact
88
+ File.join(*paths)
77
89
  end
78
90
 
79
91
  def self.project_file_paths
data/lib/au/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Au
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/au.rb CHANGED
@@ -8,7 +8,5 @@ require 'au/models/document'
8
8
  require 'au/models/repository'
9
9
  require 'au/models/staging'
10
10
 
11
- require 'pry'
12
-
13
11
  module Au
14
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: au
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edward Du
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-11-21 00:00:00.000000000 Z
13
+ date: 2018-11-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor