daun 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.codeclimate.yml +26 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +17 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/.yardopts +2 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +122 -0
- data/Rakefile +12 -0
- data/circle.yml +8 -0
- data/daun.gemspec +45 -0
- data/docs/Development.md +41 -0
- data/exe/daun +3 -0
- data/lib/daun.rb +7 -0
- data/lib/daun/cli.rb +20 -0
- data/lib/daun/refs_diff.rb +53 -0
- data/lib/daun/rugged_daun.rb +154 -0
- data/lib/daun/version.rb +3 -0
- metadata +291 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NmVhZmY4NDVhZDdkMDY5MWZkMjQ5NTBmMTU4MDJhN2Q1OGEzOWE2Mw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjRlNjQxZTIzMjRjMDQ3Y2IzNGQ0OGIxYzk1NTBjZjNiNDkyMzAxZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzM0NDI2YjViNzNjMmYyNDBlNDMwZGYxNjA1OTQyZDdhYTcwYzczNGUzZmE5
|
10
|
+
NmUyMmQxMDU3ODg2ZWJjNWEwNDE1NDAwNThjZGFmYjMwNDdhNTg1OWEzMDMx
|
11
|
+
NWEwZjMzMDY1OTRlZGMzMzYwYzI4M2YwNTkyYTE3N2I0Y2M2Njg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjUzMDQ0OWQ5YzUwOTllYzk5M2I5OTcyMzYyZTBiOGJhMzBhODczZDU0ZWYw
|
14
|
+
ODQ2ZWUzNTE5MWMyZGU3YjQ1MGMyYTA4M2I3MTkxYzIzNDE3OWUwY2YxMDU1
|
15
|
+
OGUzMjkxOWMxYmMzN2MyY2FiODNiMjZjOGEyY2M0ZDAyNzM5NTg=
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
duplication:
|
4
|
+
enabled: true
|
5
|
+
config:
|
6
|
+
languages:
|
7
|
+
- ruby:
|
8
|
+
mass_threshold: 20
|
9
|
+
- javascript
|
10
|
+
- python
|
11
|
+
- php
|
12
|
+
fixme:
|
13
|
+
enabled: true
|
14
|
+
rubocop:
|
15
|
+
enabled: true
|
16
|
+
ratings:
|
17
|
+
paths:
|
18
|
+
- "**.inc"
|
19
|
+
- "**.js"
|
20
|
+
- "**.jsx"
|
21
|
+
- "**.module"
|
22
|
+
- "**.php"
|
23
|
+
- "**.py"
|
24
|
+
- "**.rb"
|
25
|
+
exclude_paths:
|
26
|
+
- spec/
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
LineLength:
|
2
|
+
Max: 120
|
3
|
+
|
4
|
+
# Adopted from https://github.com/codeclimate/codeclimate/blame/master/config/rubocop/.rubocop.yml
|
5
|
+
Metrics/MethodLength:
|
6
|
+
Max: 30
|
7
|
+
|
8
|
+
Metrics/ModuleLength:
|
9
|
+
Max: 250
|
10
|
+
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Enabled: false
|
13
|
+
Max: 20
|
14
|
+
|
15
|
+
# Conflicts with IntelliJ auto formatting
|
16
|
+
Style/MultilineMethodCallIndentation:
|
17
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at wisen@ceilfors.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Wisen Tanasa
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
[![Build Status](https://img.shields.io/circleci/project/ceilfors/daun/master.svg?label=Build Status)](https://circleci.com/gh/ceilfors/daun/tree/master)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/ceilfors/daun/badges/gpa.svg)](https://codeclimate.com/github/ceilfors/daun)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/ceilfors/daun/badges/coverage.svg)](https://codeclimate.com/github/ceilfors/daun/coverage)
|
4
|
+
|
5
|
+
# Daun
|
6
|
+
|
7
|
+
Daun is a CLI program that will expand git branches and tags to your disk
|
8
|
+
as directories. Daun will keep the expanded directories in sync whenever there are
|
9
|
+
new, updated, or deleted tags and branches.
|
10
|
+
|
11
|
+
Daun is originally designed to help index your source code in [OpenGrok](https://opengrok.github.io/OpenGrok/).
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
#### Linux
|
16
|
+
|
17
|
+
$ gem install daun
|
18
|
+
|
19
|
+
#### Other OS
|
20
|
+
|
21
|
+
$ gem install rugged
|
22
|
+
$ gem install daun
|
23
|
+
|
24
|
+
Daun uses [`rugged`](https://github.com/libgit2/rugged) gem to talk to git repositories. As of today, this gem
|
25
|
+
can [be](https://github.com/libgit2/rugged/issues/43)
|
26
|
+
[problematic](https://github.com/libgit2/rugged/issues/489)
|
27
|
+
to be installed in OS other than Linux hence it has been made an optional dependency.
|
28
|
+
Because of this, you have to be able to install rugged gem manually first before
|
29
|
+
installing daun. Visit rugged documentation if you have problem installing rugged.
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
$ daun init [GIT_CLONE_URL] daun-repo
|
34
|
+
$ cd daun-repo
|
35
|
+
$ daun checkout
|
36
|
+
|
37
|
+
or
|
38
|
+
|
39
|
+
$ daun init [GIT_CLONE_URL] daun-repo
|
40
|
+
$ daun checkout --directory daun-repo
|
41
|
+
|
42
|
+
Subsequent calls to `checkout` will update your `daun-repo` directory with the latest
|
43
|
+
branches and tags:
|
44
|
+
|
45
|
+
- Newly created branches and tags will be added in `daun-repo`
|
46
|
+
- Updated branches and tags will be updated in `daun-repo`
|
47
|
+
- Deleted branches and tags will be deleted in `daun-repo`
|
48
|
+
|
49
|
+
The resulting output of the commands above will look like this in your
|
50
|
+
disk:
|
51
|
+
|
52
|
+
daun-repo/
|
53
|
+
.git/
|
54
|
+
branches/
|
55
|
+
master/
|
56
|
+
feature/foo/
|
57
|
+
tags/
|
58
|
+
v1.0.0/
|
59
|
+
|
60
|
+
## Options
|
61
|
+
|
62
|
+
Daun options are stored as git config. Hence you will be able to configure your `daun-repo`
|
63
|
+
just like any git repositories e.g. executing `git config` in your `daun-repo` directory or even
|
64
|
+
by setting the `global` or `system` git configuration. Visit
|
65
|
+
[git config official documentation](https://git-scm.com/docs/git-config)
|
66
|
+
for more information.
|
67
|
+
|
68
|
+
The following options are available in daun:
|
69
|
+
|
70
|
+
|
71
|
+
<table>
|
72
|
+
<tr>
|
73
|
+
<th>Name</th>
|
74
|
+
<th>Description</th>
|
75
|
+
<th>Default</th>
|
76
|
+
<th>Example</th>
|
77
|
+
</tr>
|
78
|
+
<tr>
|
79
|
+
<th>daun.branch.blacklist</th>
|
80
|
+
<td>
|
81
|
+
Branches that match the pattern set in this option will not be checked out by daun.
|
82
|
+
Multiple patterns are supported by space character. Pattern is matched by using
|
83
|
+
<code><a href="http://ruby-doc.org/core-1.9.3/File.html#method-c-fnmatch-3F">File.fnmatch?</a></code> method.
|
84
|
+
Daun will by default check out all branches. The example given will blacklist any
|
85
|
+
branches that have hotfix/ or release/ prefix.
|
86
|
+
</td>
|
87
|
+
<td>""</td>
|
88
|
+
<td>"hotfix/* release/*"</td>
|
89
|
+
</tr>
|
90
|
+
<tr>
|
91
|
+
<th>daun.tag.blacklist</th>
|
92
|
+
<td>
|
93
|
+
Tags that match the pattern set in this option will not be checked out by daun.
|
94
|
+
Multiple patterns are supported by space character. Pattern is matched by using
|
95
|
+
<code><a href="http://ruby-doc.org/core-1.9.3/File.html#method-c-fnmatch-3F">File.fnmatch?</a></code> method.
|
96
|
+
Daun will by default check out all tags. The example given will blacklist any
|
97
|
+
tags that have staged/ or build/ prefix.
|
98
|
+
</td>
|
99
|
+
<td>""</td>
|
100
|
+
<td>"staged/* build/*"</td>
|
101
|
+
</tr>
|
102
|
+
<tr>
|
103
|
+
<th>daun.tag.limit</th>
|
104
|
+
<td>
|
105
|
+
This option limits the number of tags being checked out by daun. Daun will
|
106
|
+
always keep the latest tags e.g. ordered by date.
|
107
|
+
Daun will by default check out all tags without any limit. With the example given,
|
108
|
+
daun will only check out the latest 5 tags and ignore the older ones. You can also
|
109
|
+
set this value to 0 if you don't want to check out any tags at all.
|
110
|
+
</td>
|
111
|
+
<td>-1 (unlimited)</td>
|
112
|
+
<td>5</td>
|
113
|
+
</table>
|
114
|
+
|
115
|
+
## Contributing
|
116
|
+
|
117
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ceilfors/daun. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
118
|
+
|
119
|
+
|
120
|
+
## License
|
121
|
+
|
122
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
require 'yard'
|
5
|
+
|
6
|
+
RuboCop::RakeTask.new
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
YARD::Rake::YardocTask.new do |t|
|
9
|
+
t.stats_options = %w(--list-undoc --compact)
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: [:spec, :rubocop, :yard]
|
data/circle.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
dependencies:
|
2
|
+
pre:
|
3
|
+
- rvm install rubygems 2.4.8 --force
|
4
|
+
- gem install bundler -v 1.11.2
|
5
|
+
|
6
|
+
test:
|
7
|
+
override:
|
8
|
+
- RAILS_ENV=test bundle exec rspec -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml --format documentation --color spec
|
data/daun.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'daun/version'
|
5
|
+
require 'rbconfig'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'daun'
|
9
|
+
spec.version = Daun::VERSION
|
10
|
+
spec.authors = ['Wisen Tanasa']
|
11
|
+
spec.email = ['wisen@ceilfors.com']
|
12
|
+
|
13
|
+
spec.summary = 'Expand git branches and tags to a directory'
|
14
|
+
spec.description = 'Daun is useful for source code search like OpenGrok that'\
|
15
|
+
'does not support git branches and tags by default.'
|
16
|
+
spec.homepage = 'https://github.com/ceilfors/daun'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'simplecov', '~> 0.11', '>= 0.11.2'
|
29
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.6', '>= 0.6.0'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 0.41', '>= 0.41.1'
|
31
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.2', '>= 0.2.2'
|
32
|
+
spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.4'
|
33
|
+
spec.add_development_dependency 'redcarpet', '~> 3.3', '>= 3.3.4'
|
34
|
+
|
35
|
+
spec.add_runtime_dependency 'json', '< 2' # json 2 requires ruby 2
|
36
|
+
spec.add_runtime_dependency 'thor', '~> 0.19', '>= 0.19.1'
|
37
|
+
spec.add_runtime_dependency 'logging', '~> 2.0'
|
38
|
+
|
39
|
+
if RbConfig::CONFIG['host_os'] =~ /solaris|bsd|linux/
|
40
|
+
spec.add_runtime_dependency 'rugged', '~> 0.21'
|
41
|
+
else
|
42
|
+
# Can't pull 0.24.0 yet because this depends on the libgit2 version installed locally
|
43
|
+
spec.add_development_dependency 'rugged', '~> 0.23.0'
|
44
|
+
end
|
45
|
+
end
|
data/docs/Development.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Building gem
|
2
|
+
|
3
|
+
$ bundle
|
4
|
+
$ bundle exec rake
|
5
|
+
|
6
|
+
# Install and release
|
7
|
+
|
8
|
+
|
9
|
+
To install this gem onto your local machine:
|
10
|
+
|
11
|
+
bundle exec rake install
|
12
|
+
|
13
|
+
To release a new version:
|
14
|
+
|
15
|
+
1. Update the version number in `version.rb`
|
16
|
+
2. Run `bundle exec rake release`
|
17
|
+
|
18
|
+
This step will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
19
|
+
|
20
|
+
# Mac OS X
|
21
|
+
|
22
|
+
rugged 0.24.0 can't be used easily somehow. Try to follow these steps
|
23
|
+
to install rugged successfully:
|
24
|
+
|
25
|
+
1. brew install cmake
|
26
|
+
2. brew install libgit2
|
27
|
+
3. bundle config build.rugged --use-system-libraries
|
28
|
+
4. bundle install
|
29
|
+
|
30
|
+
For the latest update of rugged, please read [its documentation](https://github.com/libgit2/rugged).
|
31
|
+
|
32
|
+
One of the problem is shown below:
|
33
|
+
|
34
|
+
Referenced from: /Users/ceilfors/.rvm/gems/ruby-1.9.3-p551/gems/rugged-0.24.0/lib/rugged/rugged.bundle
|
35
|
+
Reason: Incompatible library version: rugged.bundle requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0 - /Users/ceilfors/.rvm/gems/ruby-1.9.3-p551/gems/rugged-0.24.0/lib/rugged/rugged.bundle
|
36
|
+
from /Users/ceilfors/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:69:in `require'
|
37
|
+
from /Users/ceilfors/.rvm/gems/ruby-1.9.3-p551/gems/rugged-0.24.0/lib/rugged.rb:5:in `rescue in <top (required)>'
|
38
|
+
from /Users/ceilfors/.rvm/gems/ruby-1.9.3-p551/gems/rugged-0.24.0/lib/rugged.rb:1:in `<top (required)>'
|
39
|
+
...
|
40
|
+
|
41
|
+
|
data/exe/daun
ADDED
data/lib/daun.rb
ADDED
data/lib/daun/cli.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'daun'
|
3
|
+
|
4
|
+
module Daun
|
5
|
+
# All daun cli subcommands are made available by this class.
|
6
|
+
class CLI < Thor
|
7
|
+
desc 'init remote_url destination', 'Initialize a daun directory'
|
8
|
+
|
9
|
+
def init(remote_url, destination)
|
10
|
+
Daun::RuggedDaun.new(destination).init(remote_url)
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'checkout', 'Checks out git working tree as per daun configuration'
|
14
|
+
option :directory, default: '.'
|
15
|
+
|
16
|
+
def checkout
|
17
|
+
Daun::RuggedDaun.new(options[:directory]).checkout
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Daun
|
2
|
+
##
|
3
|
+
# Produce git refs differences before and after fetch
|
4
|
+
class RefsDiff
|
5
|
+
attr_accessor :added_remotes
|
6
|
+
|
7
|
+
# Creates a new instance of `RefsDiff`.
|
8
|
+
#
|
9
|
+
# @param before [Hash] the refs hash with full refs format as key and commit id as value
|
10
|
+
# @param after [Hash] the refs hash with full refs format as key and commit id as value
|
11
|
+
def initialize(before, after)
|
12
|
+
@before = before
|
13
|
+
@after = after
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns all of the refs that have been added after the fetch. These are the refs
|
17
|
+
# that exists in `after` but not `before`.
|
18
|
+
#
|
19
|
+
# @param type [Symbol] :tag for tag refs, :remotes for remote branches, nil for everything
|
20
|
+
def added(type = nil)
|
21
|
+
keys = (@after.keys - @before.keys).collect(&:to_s)
|
22
|
+
filter(keys, type)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns all of the refs that have been updated after the fetch. Updated refs
|
26
|
+
# are detected when refs exists in both `before` and `after` but is having a
|
27
|
+
# different commit id in the `Hash`.
|
28
|
+
#
|
29
|
+
# @param type [Symbol] :tag for tag refs, :remotes for remote branches, nil for everything
|
30
|
+
def updated(type = nil)
|
31
|
+
keys = (@after.keys + @before.keys)
|
32
|
+
.group_by { |k| k }
|
33
|
+
.select { |k, k_group| k_group.size > 1 && @before[k] != @after[k] }
|
34
|
+
.keys.collect(&:to_s)
|
35
|
+
filter(keys, type)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns all of the refs that have been deleted after the fetch. These are the
|
39
|
+
# refs that exists in `before` but not `after`
|
40
|
+
#
|
41
|
+
# @param type [Symbol] :tag for tag refs, :remotes for remote branches, nil for everything
|
42
|
+
def deleted(type = nil)
|
43
|
+
keys = (@before.keys - @after.keys).collect(&:to_s)
|
44
|
+
filter(keys, type)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def filter(keys, type)
|
50
|
+
!type.nil? ? keys.select { |k| k.start_with? "refs/#{type}" } : keys
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'rugged'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Daun
|
5
|
+
# Implementation of daun using Rugged library.
|
6
|
+
class RuggedDaun
|
7
|
+
# Creates a new RuggedDaun instance. An empty git repository will be initialized in the specified repository_path.
|
8
|
+
#
|
9
|
+
# @param repository_path [String] the path where the git repository will be created
|
10
|
+
def initialize(repository_path)
|
11
|
+
@repository = Rugged::Repository.init_at(repository_path)
|
12
|
+
@logger = Logging.logger[self]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Bootstraps the git repository with the git remote repository URL and the default daun configurations.
|
16
|
+
#
|
17
|
+
# @param remote_url [String] the git remote repository to be fetched every time {#checkout} is called
|
18
|
+
def init(remote_url)
|
19
|
+
@repository.remotes.create('origin', remote_url)
|
20
|
+
@repository.config['daun.tag.blacklist'] = ''
|
21
|
+
@repository.config['daun.tag.limit'] = '-1'
|
22
|
+
@repository.config['daun.branch.blacklist'] = ''
|
23
|
+
end
|
24
|
+
|
25
|
+
# Checkout git branches and tags in the git repository working directory.
|
26
|
+
#
|
27
|
+
# This method will fetch the latest update from `git remote origin` configured
|
28
|
+
# in the {#init} method.
|
29
|
+
# Once the references are fetch, it will detect if there are new references,
|
30
|
+
# updated references, and deleted references then act upon them
|
31
|
+
# accordingly.
|
32
|
+
def checkout
|
33
|
+
@logger.info 'Fetching git repository..'
|
34
|
+
refs_diff = fetch_refs
|
35
|
+
|
36
|
+
refs_diff.added(:remotes).each do |refs|
|
37
|
+
@logger.info "Adding #{refs}.."
|
38
|
+
checkout_remote_branch refs.to_local_branch, get_checkout_directory(refs)
|
39
|
+
end
|
40
|
+
|
41
|
+
refs_diff.updated(:remotes).each do |refs|
|
42
|
+
@logger.info "Updating #{refs}.."
|
43
|
+
checkout_remote_branch refs.to_local_branch, get_checkout_directory(refs)
|
44
|
+
end
|
45
|
+
|
46
|
+
refs_diff.deleted(:remotes).each do |refs|
|
47
|
+
@logger.info "Deleting #{refs}.."
|
48
|
+
FileUtils.rm_rf get_checkout_directory refs
|
49
|
+
end
|
50
|
+
|
51
|
+
refs_diff.added(:tags).each do |refs|
|
52
|
+
@logger.info "Adding #{refs}.."
|
53
|
+
checkout_tag refs.to_tag, get_checkout_directory(refs)
|
54
|
+
end
|
55
|
+
|
56
|
+
refs_diff.updated(:tags).each do |refs|
|
57
|
+
@logger.info "Updating #{refs}.."
|
58
|
+
checkout_tag(refs.to_tag, get_checkout_directory(refs), force: true)
|
59
|
+
end
|
60
|
+
|
61
|
+
refs_diff.deleted(:tags).each do |refs|
|
62
|
+
@logger.info "Deleting #{refs}.."
|
63
|
+
FileUtils.rm_rf get_checkout_directory refs
|
64
|
+
end
|
65
|
+
|
66
|
+
@logger.info "Finished checking out #{@repository.remotes['origin'].url} to #{@repository.workdir}"
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Fetch refs from origin.
|
72
|
+
def fetch_refs
|
73
|
+
before_fetch = Hash[@repository.refs.collect { |r| [r.name, r.target_id] }]
|
74
|
+
|
75
|
+
# Prune is not supported by rugged! Deleting all remote refs and re-fetch
|
76
|
+
delete_all_remote_branches
|
77
|
+
delete_all_tags
|
78
|
+
@repository.remotes['origin'].fetch
|
79
|
+
|
80
|
+
delete_all_remote_branches @repository.config['daun.branch.blacklist'].split
|
81
|
+
delete_all_tags @repository.config['daun.tag.blacklist'].split
|
82
|
+
if @repository.config['daun.tag.limit'].to_i > -1
|
83
|
+
keep_new_tags @repository.config['daun.tag.limit'].to_i
|
84
|
+
end
|
85
|
+
|
86
|
+
after_fetch = Hash[@repository.refs.collect { |r| [r.name, r.target_id] }]
|
87
|
+
|
88
|
+
Daun::RefsDiff.new(before_fetch, after_fetch)
|
89
|
+
end
|
90
|
+
|
91
|
+
def checkout_remote_branch(branch, target_dir)
|
92
|
+
FileUtils.mkdir_p target_dir
|
93
|
+
@repository.checkout("origin/#{branch}",
|
94
|
+
strategy: :force, target_directory: target_dir)
|
95
|
+
end
|
96
|
+
|
97
|
+
def checkout_tag(tag, target_dir, options = { force: false })
|
98
|
+
if File.exist?(target_dir) && options[:force]
|
99
|
+
# checkout --force is somehow not working to update the tag
|
100
|
+
FileUtils.rm_rf target_dir
|
101
|
+
end
|
102
|
+
FileUtils.mkdir_p target_dir
|
103
|
+
@repository.checkout(@repository.tags[tag].target.oid,
|
104
|
+
strategy: :force, target_directory: target_dir)
|
105
|
+
end
|
106
|
+
|
107
|
+
def delete_all_remote_branches(patterns = ['*'])
|
108
|
+
patterns.each do |pattern|
|
109
|
+
@repository.branches.each_name(:remote) do |branch|
|
110
|
+
if File.fnmatch? "origin/#{pattern}", branch
|
111
|
+
@repository.branches.delete branch
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def delete_all_tags(patterns = ['*'])
|
118
|
+
patterns.each do |pattern|
|
119
|
+
@repository.tags.each_name do |tag|
|
120
|
+
@repository.tags.delete tag if File.fnmatch? pattern, tag
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def keep_new_tags(limit)
|
126
|
+
@repository.tags.sort_by { |tag| tag.target.time }
|
127
|
+
.take(@repository.tags.count - limit)
|
128
|
+
.each { |t| @repository.tags.delete t.name }
|
129
|
+
end
|
130
|
+
|
131
|
+
def get_checkout_directory(refs)
|
132
|
+
if refs.start_with? 'refs/remotes'
|
133
|
+
File.join(@repository.workdir, 'branches', refs.to_local_branch)
|
134
|
+
elsif refs.start_with? 'refs/tags'
|
135
|
+
File.join(@repository.workdir, 'tags', refs.to_tag)
|
136
|
+
else
|
137
|
+
raise "#{refs} is unsupported"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Add convenience methods to grab information from git refs
|
144
|
+
class String
|
145
|
+
# Grabs branch name from git remote refs.
|
146
|
+
def to_local_branch
|
147
|
+
self[%r{refs/remotes/origin/(.*)}, 1]
|
148
|
+
end
|
149
|
+
|
150
|
+
# Grabs tag name from git tag refs.
|
151
|
+
def to_tag
|
152
|
+
self[%r{refs/tags/(.*)}, 1]
|
153
|
+
end
|
154
|
+
end
|
data/lib/daun/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,291 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: daun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wisen Tanasa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.11'
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.11.2
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0.11'
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.11.2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: codeclimate-test-reporter
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ~>
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.6'
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.6.0
|
85
|
+
type: :development
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0.6'
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.6.0
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rubocop
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0.41'
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 0.41.1
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.41'
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 0.41.1
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: rspec_junit_formatter
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0.2'
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.2.2
|
125
|
+
type: :development
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.2'
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 0.2.2
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: yard
|
137
|
+
requirement: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0.9'
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.9.4
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ~>
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0.9'
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 0.9.4
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: redcarpet
|
157
|
+
requirement: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ~>
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '3.3'
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: 3.3.4
|
165
|
+
type: :development
|
166
|
+
prerelease: false
|
167
|
+
version_requirements: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ~>
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '3.3'
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: 3.3.4
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: json
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - <
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '2'
|
182
|
+
type: :runtime
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - <
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '2'
|
189
|
+
- !ruby/object:Gem::Dependency
|
190
|
+
name: thor
|
191
|
+
requirement: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ~>
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0.19'
|
196
|
+
- - ! '>='
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: 0.19.1
|
199
|
+
type: :runtime
|
200
|
+
prerelease: false
|
201
|
+
version_requirements: !ruby/object:Gem::Requirement
|
202
|
+
requirements:
|
203
|
+
- - ~>
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0.19'
|
206
|
+
- - ! '>='
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 0.19.1
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: logging
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ~>
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '2.0'
|
216
|
+
type: :runtime
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ~>
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '2.0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: rugged
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ~>
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 0.23.0
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ~>
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 0.23.0
|
237
|
+
description: Daun is useful for source code search like OpenGrok thatdoes not support
|
238
|
+
git branches and tags by default.
|
239
|
+
email:
|
240
|
+
- wisen@ceilfors.com
|
241
|
+
executables:
|
242
|
+
- daun
|
243
|
+
extensions: []
|
244
|
+
extra_rdoc_files: []
|
245
|
+
files:
|
246
|
+
- .codeclimate.yml
|
247
|
+
- .gitignore
|
248
|
+
- .rspec
|
249
|
+
- .rubocop.yml
|
250
|
+
- .ruby-version
|
251
|
+
- .travis.yml
|
252
|
+
- .yardopts
|
253
|
+
- CODE_OF_CONDUCT.md
|
254
|
+
- Gemfile
|
255
|
+
- LICENSE.txt
|
256
|
+
- README.md
|
257
|
+
- Rakefile
|
258
|
+
- circle.yml
|
259
|
+
- daun.gemspec
|
260
|
+
- docs/Development.md
|
261
|
+
- exe/daun
|
262
|
+
- lib/daun.rb
|
263
|
+
- lib/daun/cli.rb
|
264
|
+
- lib/daun/refs_diff.rb
|
265
|
+
- lib/daun/rugged_daun.rb
|
266
|
+
- lib/daun/version.rb
|
267
|
+
homepage: https://github.com/ceilfors/daun
|
268
|
+
licenses:
|
269
|
+
- MIT
|
270
|
+
metadata: {}
|
271
|
+
post_install_message:
|
272
|
+
rdoc_options: []
|
273
|
+
require_paths:
|
274
|
+
- lib
|
275
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
276
|
+
requirements:
|
277
|
+
- - ! '>='
|
278
|
+
- !ruby/object:Gem::Version
|
279
|
+
version: '0'
|
280
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
281
|
+
requirements:
|
282
|
+
- - ! '>='
|
283
|
+
- !ruby/object:Gem::Version
|
284
|
+
version: '0'
|
285
|
+
requirements: []
|
286
|
+
rubyforge_project:
|
287
|
+
rubygems_version: 2.4.8
|
288
|
+
signing_key:
|
289
|
+
specification_version: 4
|
290
|
+
summary: Expand git branches and tags to a directory
|
291
|
+
test_files: []
|