git-amnesia 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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/bin/git-amnesia +5 -0
- data/lib/forgetful-git/amnesia.rb +20 -0
- data/lib/forgetful-git/amnesia/version.rb +3 -0
- data/lib/forgetful-git/common/git.rb +67 -0
- data/lib/forgetful-git/common/log.rb +37 -0
- data/lib/forgetful-git/common/string.rb +34 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 31691f77ee88a1ebf1fe38462cb264e9dd641176
|
4
|
+
data.tar.gz: 24c0b32b2bd2c55a827ca4f13d24584165b77400
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79e2b8465ace79a8225e876a7c39333ab0d65d4b3b8bf95c390e2a8bd82a8e94832417c4743dd9f3e9b022755707afc49a31e0b69e0e0474e15d3b078e4a641c
|
7
|
+
data.tar.gz: 195a3115c7029d1af89fed4fca680a7f2d25e25df1ef5be8e6d37ecee93a38cad4d059efd8d4226570bb2075d35ab0c92835722b4b5ffbbe4c0f1872ca7f39ca
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Armin
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/bin/git-amnesia
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'forgetful-git/common/git'
|
2
|
+
require 'forgetful-git/common/log'
|
3
|
+
|
4
|
+
class Amnesia
|
5
|
+
def self.run
|
6
|
+
repos = Git.repos
|
7
|
+
if repos.empty?
|
8
|
+
error_no_repos
|
9
|
+
end
|
10
|
+
Log.pretty_print(Git.logs(repos))
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def self.error_no_repos
|
15
|
+
puts "error: no git repositories found. please configure your repositories."
|
16
|
+
puts " git config dir.workspace /path/to/your/workspace"
|
17
|
+
puts " git config dir.others /repo:/other/repo"
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'forgetful-git/common/string'
|
2
|
+
|
3
|
+
class Git
|
4
|
+
@amnesia_count_default = 20
|
5
|
+
|
6
|
+
def self.workspace
|
7
|
+
`git config dir.workspace | envsubst`.trim
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.other_dirs
|
11
|
+
`git config dir.others | envsubst`.split_dir.explode
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.amnesia_max
|
15
|
+
count = `git config amnesia.count`.trim.to_i
|
16
|
+
if $?.exitstatus == 0
|
17
|
+
count
|
18
|
+
else
|
19
|
+
@amnesia_count_default
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.author_name
|
24
|
+
`git config user.name`.trim
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.repos
|
28
|
+
workspace = Git.workspace
|
29
|
+
repos = Git.other_dirs
|
30
|
+
if !workspace.empty?
|
31
|
+
repos += `ls #{workspace}`.explode.map do |r|
|
32
|
+
r.prepend("#{workspace}/")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
repos
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.update(repo)
|
39
|
+
`cd "#{repo}" && git fetch >/dev/null 2>/dev/null`
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.status(repo)
|
43
|
+
`cd "#{repo}" && git status -s 2>/dev/null`.explode
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.compared_to_origin(status)
|
47
|
+
if status[0].include? "[behind"
|
48
|
+
"behind"
|
49
|
+
elsif status[0].include? "[ahead"
|
50
|
+
"ahead"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.logs(repos)
|
55
|
+
logs = []
|
56
|
+
repos.each do |repo|
|
57
|
+
cmd = "cd '#{repo}' 2>/dev/null" +
|
58
|
+
" && git log --max-count=#{Git.amnesia_max} --author='#{Git.author_name}'" +
|
59
|
+
" --pretty=format:'%at::#{repo.basename}::%s' 2>/dev/null"
|
60
|
+
log = `#{cmd}`
|
61
|
+
if $?.exitstatus == 0
|
62
|
+
logs += log.explode.map { |l| Log.new(l) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
logs
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'forgetful-git/common/string'
|
3
|
+
require 'forgetful-git/common/git'
|
4
|
+
|
5
|
+
class Log
|
6
|
+
include Comparable
|
7
|
+
attr :message, :date, :repo, :timestamp
|
8
|
+
|
9
|
+
def initialize(log)
|
10
|
+
date, repo, message = log.split("::")
|
11
|
+
@timestamp = date
|
12
|
+
@date = DateTime.strptime(date,'%s').strftime("%Y-%m-%d %H:%M").to_s.yellow
|
13
|
+
@repo = repo.green
|
14
|
+
@message = message
|
15
|
+
end
|
16
|
+
|
17
|
+
def <=>(other)
|
18
|
+
other.timestamp <=> timestamp
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.pretty_print(logs)
|
22
|
+
logSubset = Log.sorted_subset(logs)
|
23
|
+
longest = Log.longest(logSubset)
|
24
|
+
logSubset.each do |log|
|
25
|
+
printf("%s %-#{longest}s: %s\n", log.date, log.repo, log.message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def self.longest(logs)
|
31
|
+
logs.map {|l| l.repo.length}.max
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.sorted_subset(logs)
|
35
|
+
logs.sort[0..Git.amnesia_max-1]
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class String
|
2
|
+
def trim
|
3
|
+
self.sub("\n", "")
|
4
|
+
end
|
5
|
+
|
6
|
+
def explode
|
7
|
+
self.split("\n")
|
8
|
+
end
|
9
|
+
|
10
|
+
def split_dir
|
11
|
+
self.sub(":", "\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
def basename
|
15
|
+
`basename "#{self}"`.trim
|
16
|
+
end
|
17
|
+
|
18
|
+
def yellow
|
19
|
+
colorize(33)
|
20
|
+
end
|
21
|
+
|
22
|
+
def green
|
23
|
+
colorize(32)
|
24
|
+
end
|
25
|
+
|
26
|
+
def blue
|
27
|
+
colorize(34)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def colorize(color_code)
|
32
|
+
"\e[#{color_code}m#{self}\e[0m"
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-amnesia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Armin Grodon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Let someone else remember what you commited
|
28
|
+
email:
|
29
|
+
- me@armingrodon.de
|
30
|
+
executables:
|
31
|
+
- git-amnesia
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.md
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- bin/git-amnesia
|
39
|
+
- lib/forgetful-git/amnesia.rb
|
40
|
+
- lib/forgetful-git/amnesia/version.rb
|
41
|
+
- lib/forgetful-git/common/git.rb
|
42
|
+
- lib/forgetful-git/common/log.rb
|
43
|
+
- lib/forgetful-git/common/string.rb
|
44
|
+
homepage: https://github.com/x4121/git-amnesia
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.9'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements:
|
63
|
+
- git
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.5.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: A tool to help you recover from your post-weekend amnesia
|
69
|
+
test_files: []
|