git-race 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/bin/git-race +88 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca02ee92d5b76e0e25e076e52da6cd68c452bebf
|
4
|
+
data.tar.gz: 6cf5c260d47505d12f3320696b5299465727bb1a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea0e1e9e47f8202c85eb185e3f41ebf5ca73dd5b87036cfe6408d12e02ba2dc2a72fc28e2ff133ce2ee2c1da8555032ba5b30cb65b162dcece14efaccf2da3bf
|
7
|
+
data.tar.gz: f25ab5ed49ff447869cc2801706cb048a9c7911f53e9ddd89a892a5aac452f108a1223a4e5c93dc535a57dc4af34e050b05e004eb63727b09a1a966004aa778d
|
data/bin/git-race
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
def query(cmd)
|
4
|
+
`#{cmd}`.chomp
|
5
|
+
end
|
6
|
+
|
7
|
+
def command(cmd)
|
8
|
+
# redirects stdout and stderr to /dev/null
|
9
|
+
system("#{cmd} > /dev/null 2>&1")
|
10
|
+
end
|
11
|
+
|
12
|
+
class Merge
|
13
|
+
attr_reader :branch, :diff, :author
|
14
|
+
|
15
|
+
def initialize(branch)
|
16
|
+
@branch = branch
|
17
|
+
@diff = conflicts_from(branch)
|
18
|
+
@author = query("git log -n1 --format='%an <%ae>' #{branch}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def conflict?
|
22
|
+
@diff.size > 0
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def conflicts_from(branch)
|
28
|
+
# you can't dry run a merge, so we have to apply and abort merges
|
29
|
+
command("git merge --no-ff --no-commit #{branch}")
|
30
|
+
query("git diff").tap do
|
31
|
+
command("git merge --abort")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
MergeRacer = Struct.new(:branch) do
|
37
|
+
MAINLINE = "origin/HEAD" # defaultly origin/master
|
38
|
+
|
39
|
+
def call
|
40
|
+
if dirty?
|
41
|
+
puts "Cowardly refusing to run, please commit your work or update .gitignore"
|
42
|
+
puts "You can figure out what files to modify with\n"
|
43
|
+
puts " git status"
|
44
|
+
elsif conflicts.none?
|
45
|
+
puts "Congratulations! Your branch doesn't conflict with anyone"
|
46
|
+
else
|
47
|
+
puts "Danger! Merge race in progress"
|
48
|
+
conflicts.each do |merge|
|
49
|
+
puts "* Conflict: #{branch} with #{merge.branch}, last authored by #{merge.author}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
puts "\n" # separator
|
54
|
+
end
|
55
|
+
|
56
|
+
def abort
|
57
|
+
puts "Abort! Abort!"
|
58
|
+
command("git merge --abort")
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def dirty?
|
64
|
+
query("git status --porcelain").length > 0
|
65
|
+
end
|
66
|
+
|
67
|
+
def conflicts
|
68
|
+
@conflicts ||= merges.select(&:conflict?)
|
69
|
+
end
|
70
|
+
|
71
|
+
def merges
|
72
|
+
branches_from_merge_base
|
73
|
+
.reject { |b| b.match(MAINLINE) }
|
74
|
+
.map { |b| Merge.new(b) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def branches_from_merge_base
|
78
|
+
query("git branch --remotes --contains #{merge_base}").split("\n").map(&:strip)
|
79
|
+
end
|
80
|
+
|
81
|
+
def merge_base
|
82
|
+
query("git merge-base #{MAINLINE} #{branch}")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
service = MergeRacer.new("HEAD")
|
87
|
+
# Signal.trap("TERM") { service.abort and exit }
|
88
|
+
service.call
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-race
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew B. Gray
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This is a script that checks branches that have happened since you branched,
|
14
|
+
and tells you if any of them are in conflict with yours.
|
15
|
+
email: himself@matthew.geek.nz
|
16
|
+
executables:
|
17
|
+
- git-race
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/git-race
|
22
|
+
homepage: https://github.com/wohyah/git-race
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.6.8
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: A merge race detector
|
46
|
+
test_files: []
|