git-conflict-blame 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/lib/git-conflict-blame.rb +69 -22
- data/lib/git-conflict-blame/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 648e9062a9e6437008a337c21b29105e904e6929
|
4
|
+
data.tar.gz: 870c341a8573536504db258ec892bf307ea20e16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fd508711a2cd336a46dc97990a0fbf71e630ecd1d93716bea0178a2d0ef3cde07d3dddcedea4eb37cd25435a840939776c225464888ced68040b6001ab28b5d
|
7
|
+
data.tar.gz: de7c8e123ffb1bce5b2b51a55921366d5f9c9da44c0c9c9d633ff1aabff709406f7ddda3c0987b3125489a81955e3e4402b18994c4d39187a083f0ce7e1b1060
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Git Conflict Blame
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/git-conflict-blame.svg)](https://badge.fury.io/rb/git-conflict-blame)
|
4
|
+
![](http://ruby-gem-downloads-badge.herokuapp.com/git-conflict-blame?type=total)
|
5
|
+
[![Inline docs](http://inch-ci.org/github/eterry1388/git-conflict-blame.svg?branch=master)](http://inch-ci.org/github/eterry1388/git-conflict-blame)
|
6
|
+
[![Dependency Status](https://gemnasium.com/eterry1388/git-conflict-blame.svg)](https://gemnasium.com/eterry1388/git-conflict-blame)
|
7
|
+
|
3
8
|
Git command that shows the blame on the lines that are in conflict. This should be ran
|
4
9
|
after a `git merge` command has been ran and there are files that are in conflict.
|
5
10
|
|
@@ -32,6 +37,7 @@ Try running one of these (depending on your OS):
|
|
32
37
|
```bash
|
33
38
|
sudo apt-get install cmake
|
34
39
|
yum install cmake
|
40
|
+
dnf install cmake
|
35
41
|
brew install cmake
|
36
42
|
```
|
37
43
|
|
@@ -45,7 +51,7 @@ nothing will be displayed.
|
|
45
51
|
#### Run this:
|
46
52
|
|
47
53
|
```bash
|
48
|
-
git conflict-blame
|
54
|
+
git conflict-blame | more
|
49
55
|
```
|
50
56
|
|
51
57
|
#### To see this:
|
data/lib/git-conflict-blame.rb
CHANGED
@@ -28,18 +28,33 @@ class GitConflictBlame
|
|
28
28
|
def run!
|
29
29
|
if conflicts?
|
30
30
|
Dir.chdir( @repo.workdir )
|
31
|
-
|
31
|
+
@submodules = find_submodules
|
32
|
+
log "#{conflict_count} files are in conflict".red
|
32
33
|
log "Parsing files to find out who is to blame..."
|
33
34
|
data, total_conflicts = find_conflict_blames
|
35
|
+
|
34
36
|
if total_conflicts == 0
|
35
|
-
|
37
|
+
if conflict_count == 0
|
38
|
+
log "All conflicts appear to be resolved".green
|
39
|
+
else
|
40
|
+
log "\nThere are #{conflict_count} files in conflict that cannot be blamed:".red
|
41
|
+
remaining_conflicted_files = cmd( 'git diff --name-only --diff-filter=U' )
|
42
|
+
log remaining_conflicted_files
|
43
|
+
if @json
|
44
|
+
data = {}
|
45
|
+
remaining_conflicted_files.split( "\n" ).each do |file_name|
|
46
|
+
data[file_name] = 'conflict cannot be blamed'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
36
50
|
else
|
37
51
|
log "#{total_conflicts} total conflicts found!\n".red
|
38
52
|
end
|
53
|
+
|
39
54
|
if @json
|
40
55
|
json_data = {
|
41
56
|
exception: false,
|
42
|
-
file_count:
|
57
|
+
file_count: conflict_count,
|
43
58
|
total_count: total_conflicts,
|
44
59
|
data: data
|
45
60
|
}
|
@@ -124,7 +139,17 @@ class GitConflictBlame
|
|
124
139
|
#
|
125
140
|
# @return [Array<String>]
|
126
141
|
def conflicts
|
127
|
-
@conflicts ||= @repo.index.conflicts.map
|
142
|
+
@conflicts ||= @repo.index.conflicts.map do |conflict|
|
143
|
+
ours = conflict[:ours]
|
144
|
+
ours[:path] if ours
|
145
|
+
end.compact
|
146
|
+
end
|
147
|
+
|
148
|
+
# Gets the total number of files that are in conflict
|
149
|
+
#
|
150
|
+
# @return [Integer] Number of files in conflict
|
151
|
+
def conflict_count
|
152
|
+
@conflict_count ||= @repo.index.conflicts.count
|
128
153
|
end
|
129
154
|
|
130
155
|
# Runs the "git blame" command
|
@@ -135,35 +160,57 @@ class GitConflictBlame
|
|
135
160
|
cmd( "git blame --show-email -c --date short #{filename}" )
|
136
161
|
end
|
137
162
|
|
163
|
+
# Find all submodules in git repo
|
164
|
+
#
|
165
|
+
# @return [Array] List of submodule paths
|
166
|
+
def find_submodules
|
167
|
+
submodules = []
|
168
|
+
current_dir = Dir.pwd
|
169
|
+
Dir.chdir( @repo.workdir )
|
170
|
+
if File.exists?( '.gitmodules' )
|
171
|
+
submodules = cmd( "grep path .gitmodules | sed 's/.*= //'" ).split( "\n" )
|
172
|
+
end
|
173
|
+
Dir.chdir( current_dir )
|
174
|
+
submodules
|
175
|
+
end
|
176
|
+
|
138
177
|
# Parses through the conflicted files and finds the blame on each line
|
139
178
|
#
|
140
179
|
# @return [Array] [data_hash, conflict_count]
|
141
180
|
def find_conflict_blames
|
142
181
|
data = {}
|
143
182
|
total_conflicts = 0
|
183
|
+
|
144
184
|
conflicts.each do |conflict|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
185
|
+
begin
|
186
|
+
next if @submodules.include?( conflict )
|
187
|
+
raw = raw_blame( conflict )
|
188
|
+
start_indexes = []
|
189
|
+
end_indexes = []
|
190
|
+
lines = raw.split( "\n" )
|
191
|
+
lines.each do |line|
|
192
|
+
start_indexes << lines.index( line ) if line.include?( '<<<<<<<' )
|
193
|
+
end_indexes << lines.index( line ) if line.include?( '>>>>>>>' )
|
194
|
+
end
|
153
195
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
196
|
+
index = 0
|
197
|
+
all_line_sets = []
|
198
|
+
start_indexes.count.times do
|
199
|
+
start_index = start_indexes[index]
|
200
|
+
end_index = end_indexes[index]
|
201
|
+
line_set = lines[start_index..end_index]
|
202
|
+
all_line_sets << parse_lines( line_set )
|
203
|
+
index += 1
|
204
|
+
end
|
205
|
+
total_conflicts += start_indexes.count
|
206
|
+
data[conflict] = all_line_sets
|
207
|
+
rescue ArgumentError
|
208
|
+
# Do nothing
|
209
|
+
# Caused by encoding issues like "invalid byte sequence in UTF-8"
|
162
210
|
end
|
163
|
-
total_conflicts += start_indexes.count
|
164
|
-
data[conflict] = all_line_sets
|
165
211
|
end
|
166
212
|
data.delete_if { |_, all_line_sets| all_line_sets.nil? || all_line_sets.empty? }
|
213
|
+
|
167
214
|
[data, total_conflicts]
|
168
215
|
end
|
169
216
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-conflict-blame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Terry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.5.1
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: Git Conflict Blame
|