git-revision 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2012 Nihad Abbasov / NARKOZ
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Git Revision
2
+
3
+ Git Revision is a simple (45 SLoC) Ruby gem that provides basic information about git source code.
4
+ You can use it in your apps, [for example](http://stackoverflow.com/q/8500644/159721), to show deployed version.
5
+
6
+ ## Installation
7
+
8
+ Add to Gemfile:
9
+
10
+ ```ruby
11
+ gem 'git-revision'
12
+ ```
13
+
14
+ and run:
15
+
16
+ ```sh
17
+ bundle install
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ `Git::Revision.info` will return the following hash:
23
+
24
+ ```ruby
25
+ {
26
+ :commit_hash => "60619c10baca6f9b4d03253697d43b7cf5d08edf",
27
+ :commit_hash_short => "60619c1",
28
+ :commit_subject => "release beta version",
29
+ :authored_date => "Fri Jun 8 17:55:01 2012 +0500",
30
+ :authored_timestamp => "1339160101",
31
+ :commit_tag => "4.2.0.beta",
32
+ :repo_last_tag => "4.2.0.beta"
33
+ }
34
+ ```
35
+
36
+ Additionally you can access these methods directly:
37
+
38
+ ```ruby
39
+ Git::Revision.commit # returns last commit hash
40
+ Git::Revision.commit_short # returns abbreviated last commit hash (7 characters)
41
+ Git::Revision.message # returns last commit message subject
42
+ Git::Revision.date # returns authored date of last commit
43
+ Git::Revision.timestamp # returns authored date of last commit in Unix time
44
+ Git::Revision.tag # returns last commit tag if exists
45
+ Git::Revision.last_tag # returns last tag in repository if exists
46
+ ```
47
+
48
+ ## License
49
+
50
+ Released under the BSD 2-clause license. See LICENSE.txt for details.
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'git-revision'
3
+ gem.version = '0.0.1'
4
+ gem.files = `git ls-files`.split($\)
5
+ gem.require_path = 'lib'
6
+ gem.license = 'BSD'
7
+
8
+ gem.author = 'Nihad Abbasov'
9
+ gem.email = 'mail@narkoz.me'
10
+ gem.summary = 'Git Revision provides information about git source code.'
11
+ gem.homepage = 'http://github.com/narkoz/git-revision'
12
+ end
@@ -0,0 +1,45 @@
1
+ module Git
2
+ class Revision
3
+ class << self
4
+ def commit
5
+ `git log -1 --pretty="format:%H"`
6
+ end
7
+
8
+ def commit_short
9
+ `git log -1 --pretty="format:%h"`
10
+ end
11
+
12
+ def message
13
+ `git log -1 --pretty="format:%s"`
14
+ end
15
+
16
+ def date
17
+ `git log -1 --pretty="format:%ad"`
18
+ end
19
+
20
+ def timestamp
21
+ `git log -1 --pretty="format:%at"`
22
+ end
23
+
24
+ def tag
25
+ `git describe --exact-match #{commit}`.strip
26
+ end
27
+
28
+ def last_tag
29
+ `git describe --tags --abbrev=0`.strip
30
+ end
31
+
32
+ def info
33
+ @info ||= {
34
+ :commit_hash => commit,
35
+ :commit_hash_short => commit_short,
36
+ :commit_subject => message,
37
+ :authored_date => date,
38
+ :authored_timestamp => timestamp,
39
+ :commit_tag => tag,
40
+ :repo_last_tag => last_tag
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-revision
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nihad Abbasov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: mail@narkoz.me
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - git-revision.gemspec
23
+ - lib/git-revision.rb
24
+ homepage: http://github.com/narkoz/git-revision
25
+ licenses:
26
+ - BSD
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.24
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Git Revision provides information about git source code.
49
+ test_files: []
50
+ has_rdoc: