git_bpf 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/lib/git_bpf/commands/init.rb +54 -4
- data/lib/git_bpf/commands/recreate-branch.rb +36 -5
- data/lib/git_bpf/hooks/post-checkout.rb +6 -1
- data/lib/git_bpf/hooks/post-commit.rb +16 -0
- data/lib/git_bpf/lib/git-helpers.rb +6 -2
- data/lib/git_bpf/lib/repository.rb +2 -2
- data/lib/git_bpf/version.rb +1 -1
- metadata +4 -4
- data/lib/git_bpf/hooks/post-merge.rb +0 -11
data/README.md
CHANGED
@@ -63,6 +63,9 @@ git_bpf is packaged as a Ruby Gem and hosted on [RubyGems]
|
|
63
63
|
- If <target-repository> is not provided, <target-repository> defaults to your current directory (will fail if current directory is not a git repository).
|
64
64
|
- The script requires the <target-repository> to have a remote named 'origin'.
|
65
65
|
|
66
|
+
## Upgrading
|
67
|
+
|
68
|
+
Upgrading from older development versions of these scripts is a little bit sketchy. The steps possible steps involved are detailed [here](https://gist.github.com/tnightingale/59f44847526e1cc20bf7). Read through the document and run the steps that apply to you.
|
66
69
|
|
67
70
|
[Branch-per-Feature]: https://github.com/affinitybridge/git-bpf/wiki/Branch-per-feature-process
|
68
71
|
[RubyGems]: http://rubygems.org/
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'git_bpf/lib/gitflow'
|
2
2
|
require 'git_bpf/lib/git-helpers'
|
3
3
|
require 'git_bpf/lib/repository'
|
4
|
+
require 'Find'
|
4
5
|
|
5
6
|
#
|
6
7
|
# init:
|
@@ -29,16 +30,63 @@ class Init < GitFlow/'init'
|
|
29
30
|
]
|
30
31
|
end
|
31
32
|
|
33
|
+
# Removes all aliases to git-bpf commands.
|
34
|
+
def removeCommandAliases(repo)
|
35
|
+
config = repo.config(true, '--list').lines.each do |line|
|
36
|
+
next unless line.start_with? 'alias.' and line.match /\!_git\-bpf/
|
37
|
+
a = /alias\.([a-zA-Z0-9\-_]+)\=(.)*/.match(line)[1]
|
38
|
+
repo.config(true, '--unset', "alias.#{a}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Removes all symlinks to targets within source_location that are found
|
43
|
+
# within path.
|
44
|
+
def rmSymlinks(path, source_location)
|
45
|
+
targets_to_check = [source_location]
|
46
|
+
all_targets = []
|
47
|
+
|
48
|
+
# Find all symlink targets that represent a path within source_location.
|
49
|
+
while targets_to_check.length > 0
|
50
|
+
git_bpf_target = targets_to_check.pop
|
51
|
+
Find.find(path) do |p|
|
52
|
+
if File.symlink?(p)
|
53
|
+
target = File.readlink(p)
|
54
|
+
if target.include? git_bpf_target and not targets_to_check.include? p
|
55
|
+
targets_to_check.push p
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
all_targets.push git_bpf_target
|
60
|
+
end
|
61
|
+
|
62
|
+
# Now delete any symlink whose target path includes any of the paths we
|
63
|
+
# have identified.
|
64
|
+
Find.find(path) do |p|
|
65
|
+
if File.symlink? p
|
66
|
+
target = File.readlink p
|
67
|
+
all_targets.each do |t|
|
68
|
+
if target.include? t
|
69
|
+
File.unlink p
|
70
|
+
break
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
32
77
|
def execute(opts, argv)
|
33
78
|
if argv.length > 1
|
34
79
|
run 'init', '--help'
|
35
80
|
terminate
|
36
81
|
end
|
37
82
|
|
38
|
-
|
39
|
-
source_path = File.join File.dirname(__FILE__), '..'
|
83
|
+
source_path = File.expand_path("..", File.dirname(__FILE__))
|
40
84
|
target = Repository.new(argv.length == 1 ? argv.pop : Dir.getwd)
|
41
85
|
|
86
|
+
# Perform some cleanup in case this repo was previously initalized.
|
87
|
+
target.config(true, '--remove-section', 'gitbpf') rescue nil
|
88
|
+
removeCommandAliases target
|
89
|
+
rmSymlinks(target.git_dir, source_path)
|
42
90
|
|
43
91
|
#
|
44
92
|
# 1. Link source scripts directory.
|
@@ -80,11 +128,13 @@ class Init < GitFlow/'init'
|
|
80
128
|
target.config(true, "rerere.enabled", "true")
|
81
129
|
target.config(true, "rerere.autoupdate", "true")
|
82
130
|
|
131
|
+
target.config(true, "gitbpf.remotename", opts.remote_name)
|
132
|
+
|
83
133
|
rerere_path = File.join(target.git_dir, 'rr-cache')
|
84
134
|
target_remote_url = target.remoteUrl(opts.remote_name)
|
85
135
|
|
86
136
|
if not File.directory? rerere_path
|
87
|
-
rerere = Repository::clone target_remote_url, rerere_path
|
137
|
+
rerere = Repository::clone target_remote_url, rerere_path, opts.remote_name
|
88
138
|
elsif not File.directory? File.join(rerere_path, '.git')
|
89
139
|
opoo "Rerere cache directory already exists; Initializing repository in existing rr-cache directory."
|
90
140
|
rerere = Repository.init rerere_path
|
@@ -115,7 +165,7 @@ class Init < GitFlow/'init'
|
|
115
165
|
#
|
116
166
|
hooks_dir = File.join(target.git_dir, "hooks")
|
117
167
|
hooks = [
|
118
|
-
'post-
|
168
|
+
'post-commit',
|
119
169
|
'post-checkout'
|
120
170
|
]
|
121
171
|
|
@@ -30,6 +30,13 @@ class RecreateBranch < GitFlow/'recreate-branch'
|
|
30
30
|
['-l', '--list',
|
31
31
|
"Process source branch for merge commits and list them. Will not make any changes to any branches.",
|
32
32
|
lambda { |n| opts.list = true }],
|
33
|
+
['-d', '--discard',
|
34
|
+
"Discard the existing local source branch and checkout a new source branch from the remote if one exists. If no remote is specified with -r, gitbpf will use the configured remote, or origin if none is configured.",
|
35
|
+
lambda { |n| opts.discard = true }],
|
36
|
+
['-r', '--remote NAME',
|
37
|
+
"Specify the remote repository to work with. Only works with the -d option.",
|
38
|
+
lambda { |n| opts.remote = n }],
|
39
|
+
|
33
40
|
]
|
34
41
|
end
|
35
42
|
|
@@ -44,6 +51,28 @@ class RecreateBranch < GitFlow/'recreate-branch'
|
|
44
51
|
# If no new branch name provided, replace the source branch.
|
45
52
|
opts.branch = source if opts.branch == nil
|
46
53
|
|
54
|
+
if not refExists? opts.base
|
55
|
+
terminate "Cannot find reference '#{opts.base}' to use as a base for new branch: #{opts.branch}."
|
56
|
+
end
|
57
|
+
|
58
|
+
if opts.discard
|
59
|
+
unless opts.remote
|
60
|
+
repo = Repository.new(Dir.getwd)
|
61
|
+
remote_name = repo.config(true, "--get", "gitbpf.remotename").chomp
|
62
|
+
opts.remote = remote_name.empty? ? 'origin' : remote_name
|
63
|
+
end
|
64
|
+
git('fetch', opts.remote)
|
65
|
+
if branchExists?(source, opts.remote)
|
66
|
+
opoo "This will delete your local '#{source}' branch if it exists and create it afresh from the #{opts.remote} remote."
|
67
|
+
if not promptYN "Continue?"
|
68
|
+
terminate "Aborting."
|
69
|
+
end
|
70
|
+
git('checkout', opts.base)
|
71
|
+
git('branch', '-D', source) if branchExists? source
|
72
|
+
git('checkout', source)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
47
76
|
# Perform some validation.
|
48
77
|
if not branchExists? source
|
49
78
|
terminate "Cannot recreate branch #{source} as it doesn't exist."
|
@@ -53,10 +82,6 @@ class RecreateBranch < GitFlow/'recreate-branch'
|
|
53
82
|
terminate "Cannot create branch #{opts.branch} as it already exists."
|
54
83
|
end
|
55
84
|
|
56
|
-
if not refExists? opts.base
|
57
|
-
terminate "Cannot find reference '#{opts.base}' to use as a base for new branch: #{opts.branch}."
|
58
|
-
end
|
59
|
-
|
60
85
|
#
|
61
86
|
# 1. Compile a list of merged branches from source branch.
|
62
87
|
#
|
@@ -169,7 +194,13 @@ class RecreateBranch < GitFlow/'recreate-branch'
|
|
169
194
|
alt_base = git('name-rev', base, '--name-only').strip
|
170
195
|
remote_heads = /remote\/\w+\/HEAD/
|
171
196
|
unless name.include? source or name.include? alt_base or name.match remote_heads
|
172
|
-
|
197
|
+
# Make sure not to include the tilde part of a branch name (e.g. '~2')
|
198
|
+
# as this signifies a commit that's behind the head of the branch but
|
199
|
+
# we want to merge in the head of the branch.
|
200
|
+
name = name.partition('~')[0]
|
201
|
+
# This can lead to duplicate branches, because the name may have only
|
202
|
+
# differed in the tilde portion ('mybranch~1', 'mybranch~2', etc.)
|
203
|
+
branches.push name unless branches.include? name
|
173
204
|
end
|
174
205
|
end
|
175
206
|
end
|
@@ -1,4 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# Pull latest conflict resolutions.
|
4
|
-
`git
|
4
|
+
remote_name = `git config --get gitbpf.remotename`.chomp
|
5
|
+
if remote_name.empty?
|
6
|
+
STDERR.puts "You have not configured the remote repository to be used by git-bpf. This is needed for rerere sharing. To use the 'origin' remote, run \n \`git config gitbpf.remotename 'origin'\`\n You can specify a remote name of your choosing."
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
`git share-rerere pull -r #{remote_name}`
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
parents = `git rev-list -n 1 --parents HEAD`.split("\s")
|
4
|
+
|
5
|
+
# Shift off the last commit.
|
6
|
+
last = parents.shift
|
7
|
+
|
8
|
+
if parents.length >= 2
|
9
|
+
remote_name = `git config --get gitbpf.remotename`.chomp
|
10
|
+
if remote_name.empty?
|
11
|
+
STDERR.puts "You have not configured the remote repository to be used by git-bpf. This is needed for rerere sharing. To use the 'origin' remote, run \n \`git config gitbpf.remotename 'origin'\`\n You can specify a remote name of your choosing."
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
`git share-rerere pull -r #{remote_name}`
|
15
|
+
`git share-rerere push -r #{remote_name}`
|
16
|
+
end
|
@@ -83,8 +83,12 @@ module GitHelpersMixin
|
|
83
83
|
return params + args
|
84
84
|
end
|
85
85
|
|
86
|
-
def branchExists?(branch)
|
87
|
-
|
86
|
+
def branchExists?(branch, remote = nil)
|
87
|
+
if remote
|
88
|
+
ref = "refs/remotes/#{remote}/#{branch}"
|
89
|
+
else
|
90
|
+
ref = (branch.include? "refs/heads/") ? branch : "refs/heads/#{branch}"
|
91
|
+
end
|
88
92
|
begin
|
89
93
|
git('show-ref', '--verify', '--quiet', ref)
|
90
94
|
rescue
|
data/lib/git_bpf/version.rb
CHANGED
metadata
CHANGED
@@ -3,10 +3,10 @@ name: git_bpf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
+
- 1
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.2
|
9
|
+
version: 1.0.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- tnightingale
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2013-
|
17
|
+
date: 2013-09-09 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -66,7 +66,7 @@ files:
|
|
66
66
|
- lib/git_bpf/commands/recreate-branch.rb
|
67
67
|
- lib/git_bpf/commands/share-rerere-cache.rb
|
68
68
|
- lib/git_bpf/hooks/post-checkout.rb
|
69
|
-
- lib/git_bpf/hooks/post-
|
69
|
+
- lib/git_bpf/hooks/post-commit.rb
|
70
70
|
- lib/git_bpf/lib/git-helpers.rb
|
71
71
|
- lib/git_bpf/lib/gitflow.rb
|
72
72
|
- lib/git_bpf/lib/repository.rb
|