git_reflow 0.8.10 → 0.9.0
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 +4 -4
- data/.rubocop.yml +2 -0
- data/.ruby-version +1 -1
- data/Appraisals +1 -6
- data/CHANGELOG.md +426 -348
- data/Gemfile.lock +15 -19
- data/LICENSE +20 -20
- data/README.md +27 -7
- data/Rakefile +8 -8
- data/bin/console +7 -7
- data/bin/setup +6 -6
- data/circle.yml +5 -5
- data/exe/git-reflow +9 -30
- data/git_reflow.gemspec +1 -2
- data/lib/git_reflow/config.rb +22 -13
- data/lib/git_reflow/git_helpers.rb +69 -22
- data/lib/git_reflow/git_server/base.rb +68 -68
- data/lib/git_reflow/git_server/git_hub/pull_request.rb +15 -13
- data/lib/git_reflow/git_server/pull_request.rb +4 -2
- data/lib/git_reflow/merge_error.rb +9 -9
- data/lib/git_reflow/rspec/command_line_helpers.rb +9 -1
- data/lib/git_reflow/rspec/stub_helpers.rb +13 -13
- data/lib/git_reflow/rspec/workflow_helpers.rb +18 -0
- data/lib/git_reflow/rspec.rb +1 -0
- data/lib/git_reflow/sandbox.rb +1 -0
- data/lib/git_reflow/version.rb +1 -1
- data/lib/git_reflow/workflow.rb +277 -9
- data/lib/git_reflow/workflows/FlatMergeWorkflow +38 -0
- data/lib/git_reflow/workflows/core.rb +208 -79
- data/lib/git_reflow.rb +3 -14
- data/spec/fixtures/awesome_workflow.rb +2 -6
- data/spec/fixtures/git/git_config +7 -7
- data/spec/fixtures/issues/comment.json.erb +27 -27
- data/spec/fixtures/issues/comments.json +29 -29
- data/spec/fixtures/issues/comments.json.erb +15 -15
- data/spec/fixtures/pull_requests/comment.json.erb +45 -45
- data/spec/fixtures/pull_requests/comments.json +47 -47
- data/spec/fixtures/pull_requests/comments.json.erb +15 -15
- data/spec/fixtures/pull_requests/commits.json +29 -29
- data/spec/fixtures/pull_requests/external_pull_request.json +145 -145
- data/spec/fixtures/pull_requests/pull_request.json +142 -142
- data/spec/fixtures/pull_requests/pull_request.json.erb +142 -142
- data/spec/fixtures/pull_requests/pull_request_branch_nonexistent_error.json +32 -0
- data/spec/fixtures/pull_requests/pull_request_exists_error.json +32 -32
- data/spec/fixtures/pull_requests/pull_requests.json +136 -136
- data/spec/fixtures/repositories/commit.json +53 -53
- data/spec/fixtures/repositories/commit.json.erb +53 -53
- data/spec/fixtures/repositories/commits.json.erb +13 -13
- data/spec/fixtures/repositories/statuses.json +31 -31
- data/spec/lib/git_reflow/git_helpers_spec.rb +115 -12
- data/spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb +6 -6
- data/spec/lib/git_reflow/git_server/pull_request_spec.rb +9 -3
- data/spec/lib/git_reflow/workflow_spec.rb +190 -11
- data/spec/lib/git_reflow/workflows/core_spec.rb +224 -65
- data/spec/lib/git_reflow/workflows/flat_merge_spec.rb +17 -6
- data/spec/lib/git_reflow_spec.rb +2 -25
- data/spec/spec_helper.rb +3 -0
- data/spec/support/github_helpers.rb +1 -1
- data/spec/support/mock_pull_request.rb +17 -17
- data/spec/support/web_mocks.rb +39 -39
- metadata +9 -28
- data/lib/git_reflow/commands/deliver.rb +0 -10
- data/lib/git_reflow/commands/refresh.rb +0 -20
- data/lib/git_reflow/commands/review.rb +0 -13
- data/lib/git_reflow/commands/setup.rb +0 -11
- data/lib/git_reflow/commands/stage.rb +0 -9
- data/lib/git_reflow/commands/start.rb +0 -18
- data/lib/git_reflow/commands/status.rb +0 -7
- data/lib/git_reflow/workflows/flat_merge.rb +0 -10
- data/spec/fixtures/workflow_with_super.rb +0 -8
data/Gemfile.lock
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
git_reflow (0.
|
4
|
+
git_reflow (0.9.0)
|
5
5
|
colorize (>= 0.7.0)
|
6
|
-
github_api (= 0.
|
7
|
-
gli (= 2.17.0)
|
6
|
+
github_api (= 0.18.2)
|
8
7
|
highline
|
9
8
|
httpclient
|
10
9
|
reenhanced_bitbucket_api (= 0.3.2)
|
@@ -30,30 +29,27 @@ GEM
|
|
30
29
|
multipart-post (>= 1.2, < 3)
|
31
30
|
faraday_middleware (0.9.2)
|
32
31
|
faraday (>= 0.7.4, < 0.10)
|
33
|
-
github_api (0.
|
34
|
-
addressable (~> 2.4
|
32
|
+
github_api (0.18.2)
|
33
|
+
addressable (~> 2.4)
|
35
34
|
descendants_tracker (~> 0.0.4)
|
36
|
-
faraday (~> 0.8
|
37
|
-
hashie (>= 3.
|
38
|
-
mime-types (>= 1.16, < 3.0)
|
35
|
+
faraday (~> 0.8)
|
36
|
+
hashie (~> 3.5, >= 3.5.2)
|
39
37
|
oauth2 (~> 1.0)
|
40
|
-
gli (2.17.0)
|
41
38
|
hashdiff (0.3.7)
|
42
|
-
hashie (3.
|
43
|
-
highline (
|
39
|
+
hashie (3.6.0)
|
40
|
+
highline (2.0.0)
|
44
41
|
httpclient (2.8.3)
|
45
|
-
jwt (1.
|
42
|
+
jwt (2.1.0)
|
46
43
|
method_source (0.9.0)
|
47
|
-
mime-types (2.99.3)
|
48
44
|
mini_portile2 (2.3.0)
|
49
45
|
multi_json (1.13.1)
|
50
46
|
multi_xml (0.6.0)
|
51
47
|
multipart-post (2.0.0)
|
52
|
-
nokogiri (1.8.
|
48
|
+
nokogiri (1.8.5)
|
53
49
|
mini_portile2 (~> 2.3.0)
|
54
|
-
oauth2 (1.4.
|
55
|
-
faraday (>= 0.8, < 0.
|
56
|
-
jwt (
|
50
|
+
oauth2 (1.4.1)
|
51
|
+
faraday (>= 0.8, < 0.16.0)
|
52
|
+
jwt (>= 1.0, < 3.0)
|
57
53
|
multi_json (~> 1.3)
|
58
54
|
multi_xml (~> 0.5)
|
59
55
|
rack (>= 1.2, < 3)
|
@@ -63,7 +59,7 @@ GEM
|
|
63
59
|
pry-byebug (3.6.0)
|
64
60
|
byebug (~> 10.0)
|
65
61
|
pry (~> 0.10)
|
66
|
-
rack (2.0.
|
62
|
+
rack (2.0.6)
|
67
63
|
rake (12.3.1)
|
68
64
|
rdoc (6.0.3)
|
69
65
|
reenhanced_bitbucket_api (0.3.2)
|
@@ -112,4 +108,4 @@ DEPENDENCIES
|
|
112
108
|
wwtd (= 1.3.0)
|
113
109
|
|
114
110
|
BUNDLED WITH
|
115
|
-
1.
|
111
|
+
1.17.1
|
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2014 Reenhanced L.L.C.
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
7
|
-
the Software without restriction, including without limitation the rights to
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
-
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, FITNESS
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Reenhanced L.L.C.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
<img alt="Circle CI" src="https://circleci.com/gh/reenhanced/gitreflow.svg?style=svg&circle-token=d94825c17c7e33558dc2a82b37afad7b558e5a12">
|
9
9
|
</a>
|
10
10
|
<a href="https://github.com/reenhanced/gitreflow" title="git workflow">
|
11
|
-
<img alt="Git workflow powered by git-reflow" src="https://img.shields.io/badge/git--reflow-v0.
|
11
|
+
<img alt="Git workflow powered by git-reflow" src="https://img.shields.io/badge/git--reflow-v0.9.0-blue.svg?style=flat">
|
12
12
|
</a>
|
13
13
|
<a href="http://inch-ci.org/github/reenhanced/gitreflow" title="documentation coverage">
|
14
14
|
<img src="http://inch-ci.org/github/reenhanced/gitreflow.svg?branch=master&style=shields" alt="Git-Reflow Documentation" />
|
@@ -117,7 +117,7 @@ This sets up a feature branch remotely and brings a local copy to your machine.
|
|
117
117
|
|
118
118
|
`git reflow start` takes in the name of the new branch name that you want to create your feature on.
|
119
119
|
In addition, it takes in an optional flag of a _base-branch_ name (`--base`). If you don't pass in this parameter,
|
120
|
-
then it
|
120
|
+
then it will look up the `reflow.base-branch` git configuration or default to "master". The base branch name is the base branch that you want to base your feature off of.
|
121
121
|
This ensures that every time you start a new base branch, it will be based off of your latest remote base.
|
122
122
|
|
123
123
|
git reflow start nh-branch-name --base base-branch-name
|
@@ -137,6 +137,9 @@ git reflow refresh -r <remote-location> -b <base-branch>
|
|
137
137
|
|
138
138
|
You pass in the name of the remote to fetch from and the name of the **base-branch** that you would like to merge into your **feature-branch**. The **remote-location** defaults to `origin` and the base-branch defaults to `master`. This command also takes in remote and branch name as flag options.
|
139
139
|
|
140
|
+
> **Note:** If no `base-branch` argument is provided, then we'll look for a `reflow.base-branch` git
|
141
|
+
> configuration and fallback to `master` as the default.
|
142
|
+
|
140
143
|
### Reviewing your work
|
141
144
|

|
142
145
|
```
|
@@ -150,9 +153,11 @@ We assume you know what you're doing, so if you need something different, do it
|
|
150
153
|
|
151
154
|
After making commits to your branch, run `review`. Didn't push it up? No problem, we'll do it for you.
|
152
155
|
```
|
153
|
-
git reflow review -t <title> -m <message>
|
156
|
+
git reflow review -t <title> -m <message> <base-branch>
|
154
157
|
```
|
155
|
-
> **Note:** `-t` and `-m` are optional.
|
158
|
+
> **Note:** `-t` and `-m` are optional, as is the `base-branch` argument. If no
|
159
|
+
> base-branch is provided, then we'll look for a `reflow.base-branch` git
|
160
|
+
> configuration and fallback to `master` as the default.
|
156
161
|
|
157
162
|
If you do not pass the title or message options to the review command, you will be given an editor to write your PR request commit message, similar to `git commit`. The first line is the title, the rest is the body.
|
158
163
|
|
@@ -202,9 +207,12 @@ If not, create it and print "Pull request created at http://pull-url/". If so, p
|
|
202
207
|
### Checking your branch status
|
203
208
|

|
204
209
|
```
|
205
|
-
git reflow status
|
210
|
+
git reflow status <base-branch>
|
206
211
|
```
|
207
212
|
|
213
|
+
> **Note:** If no `base-branch` is provided, then we'll look for a `reflow.base-branch` git
|
214
|
+
> configuration and fallback to `master` as the default.
|
215
|
+
|
208
216
|
Sometimes you start working on a branch and can't get back to it for a while. It happens. Use +status+ to check on the status of your work.
|
209
217
|
|
210
218
|
```
|
@@ -226,10 +234,13 @@ to find out where your pull request is at. But in case you want to take a look,
|
|
226
234
|
### Delivering approved code
|
227
235
|

|
228
236
|
```
|
229
|
-
git reflow deliver
|
237
|
+
git reflow deliver <base-branch>
|
230
238
|
```
|
231
239
|
|
232
|
-
> **Note:**
|
240
|
+
> **Note:** If no `base-branch` argument is provided, then we'll look for a `reflow.base-branch` git
|
241
|
+
> configuration and fallback to `master` as the default.
|
242
|
+
|
243
|
+
> **Also:** This documentation is for the process for the github "remote" merge process via the github_api.
|
233
244
|
For the bitbucket standard or github manual process (used when the user applies -f force flag to the "remote" merge via the github_api), please go to section B.
|
234
245
|
|
235
246
|
|
@@ -443,6 +454,15 @@ If the review is done, it's time to merge. Here's what happens:
|
|
443
454
|
|
444
455
|
See our [Advanced Usage](https://github.com/reenhanced/gitreflow/wiki/Full-List-of-Configuration-Options) for more ways you can customize your workflow.
|
445
456
|
|
457
|
+
## Customization
|
458
|
+
|
459
|
+
Git-reflow's default process isn't meant to fit every team, which is why we've introduced [Custom Workflows](https://github.com/reenhanced/gitreflow/wiki/Custom-Workflows). With a custom workflow, you can:
|
460
|
+
|
461
|
+
* Add hooks to be run before, or after any command
|
462
|
+
* Use one of our pre-configured workflows as a basis for your own
|
463
|
+
* Override any of the default commands
|
464
|
+
* Create new commands
|
465
|
+
|
446
466
|
---
|
447
467
|
|
448
468
|
## Contributing
|
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
require "bundler/gem_tasks"
|
3
|
-
require "rspec/core/rake_task"
|
4
|
-
|
5
|
-
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
|
7
|
-
task :default => :spec
|
8
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "git_reflow"
|
5
|
-
|
6
|
-
require "irb"
|
7
|
-
IRB.start
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "git_reflow"
|
5
|
+
|
6
|
+
require "irb"
|
7
|
+
IRB.start
|
data/bin/setup
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
data/circle.yml
CHANGED
@@ -7,12 +7,12 @@ dependencies:
|
|
7
7
|
- >
|
8
8
|
case $CIRCLE_NODE_INDEX in
|
9
9
|
0)
|
10
|
-
rvm-exec 2.3.
|
11
|
-
rvm-exec 2.3.
|
10
|
+
rvm-exec 2.3.8 gem install bundler
|
11
|
+
rvm-exec 2.3.8 bash -c "bundle check --path=vendor/bundle_2.3 || bundle install --path=vendor/bundle_2.3"
|
12
12
|
;;
|
13
13
|
1)
|
14
|
-
rvm-exec 2.4.
|
15
|
-
rvm-exec 2.4.
|
14
|
+
rvm-exec 2.4.5 gem install bundler
|
15
|
+
rvm-exec 2.4.5 bash -c "bundle check --path=vendor/bundle_2.4 || bundle install --path=vendor/bundle_2.4"
|
16
16
|
;;
|
17
17
|
2)
|
18
18
|
rvm-exec ruby-head gem install bundler
|
@@ -22,5 +22,5 @@ dependencies:
|
|
22
22
|
|
23
23
|
test:
|
24
24
|
override:
|
25
|
-
- case $CIRCLE_NODE_INDEX in 0) rvm-exec 2.3.
|
25
|
+
- case $CIRCLE_NODE_INDEX in 0) rvm-exec 2.3.8 bundle exec rake ;; 1) rvm-exec 2.4.5 bundle exec rake ;; 2) rvm-exec ruby-head bundle exec rake ;; esac:
|
26
26
|
parallel: true
|
data/exe/git-reflow
CHANGED
@@ -1,36 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
3
3
|
require 'rubygems'
|
4
|
-
require 'gli'
|
5
4
|
require 'git_reflow'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# Pre logic here
|
17
|
-
# Return true to proceed; false to abourt and not call the
|
18
|
-
# chosen command
|
19
|
-
# Use skips_pre before a command to skip this block
|
20
|
-
# on that command only
|
21
|
-
true
|
6
|
+
reflow_command = ARGV.shift
|
7
|
+
if reflow_command.nil? || GitReflow.workflow.commands[reflow_command.to_sym].nil?
|
8
|
+
GitReflow.help
|
9
|
+
elsif ARGV.include? "--help"
|
10
|
+
GitReflow.documentation_for_command(reflow_command)
|
11
|
+
else
|
12
|
+
command_options = GitReflow.parse_command_options!(reflow_command)
|
13
|
+
GitReflow.logger.debug "Running command `#{reflow_command}` with options: #{command_options.inspect}"
|
14
|
+
GitReflow.public_send(reflow_command.to_sym, command_options)
|
22
15
|
end
|
23
|
-
|
24
|
-
post do |global,command,options,args|
|
25
|
-
# Post logic here
|
26
|
-
# Use skips_post before a command to skip this
|
27
|
-
# block on that command only
|
28
|
-
end
|
29
|
-
|
30
|
-
on_error do |exception|
|
31
|
-
# Error logic here
|
32
|
-
# return false to skip default error handling
|
33
|
-
true
|
34
|
-
end
|
35
|
-
|
36
|
-
exit run(ARGV)
|
data/git_reflow.gemspec
CHANGED
@@ -29,10 +29,9 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.add_development_dependency('wwtd', '1.3.0')
|
30
30
|
|
31
31
|
s.add_dependency('colorize', '>= 0.7.0')
|
32
|
-
s.add_dependency('gli', '2.17.0')
|
33
32
|
s.add_dependency('highline')
|
34
33
|
s.add_dependency('httpclient')
|
35
|
-
s.add_dependency('github_api', '0.
|
34
|
+
s.add_dependency('github_api', '0.18.2')
|
36
35
|
s.add_dependency('reenhanced_bitbucket_api', '0.3.2')
|
37
36
|
|
38
37
|
s.post_install_message = "You need to setup your GitHub OAuth token\nPlease run 'git-reflow setup'"
|
data/lib/git_reflow/config.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GitReflow
|
4
|
+
# This is a utility module for getting and setting git-config variables.
|
2
5
|
module Config
|
3
|
-
|
6
|
+
CONFIG_FILE_PATH = "#{ENV['HOME']}/.gitconfig.reflow"
|
4
7
|
|
5
|
-
|
8
|
+
module_function
|
6
9
|
|
7
10
|
def get(key, reload: false, all: false, local: false)
|
8
|
-
|
9
|
-
|
11
|
+
return cached_git_config_value(key) unless reload || cached_git_config_value(key).empty?
|
12
|
+
|
13
|
+
local = local ? '--local ' : ''
|
14
|
+
if all
|
15
|
+
new_value = GitReflow::Sandbox.run("git config #{local}--get-all #{key}", loud: false, blocking: false)
|
10
16
|
else
|
11
|
-
|
12
|
-
if all
|
13
|
-
new_value = GitReflow::Sandbox.run("git config #{local}--get-all #{key}", loud: false, blocking: false)
|
14
|
-
else
|
15
|
-
new_value = GitReflow::Sandbox.run("git config #{local}--get #{key}", loud: false, blocking: false)
|
16
|
-
end
|
17
|
-
instance_variable_set(:"@#{key.tr('.-', '_')}", new_value.strip)
|
17
|
+
new_value = GitReflow::Sandbox.run("git config #{local}--get #{key}", loud: false, blocking: false)
|
18
18
|
end
|
19
|
+
cache_git_config_key(key, new_value)
|
19
20
|
end
|
20
21
|
|
21
22
|
def set(key, value, local: false)
|
22
|
-
value =
|
23
|
+
value = value.to_s.strip
|
23
24
|
if local
|
24
25
|
GitReflow::Sandbox.run "git config --replace-all #{key} \"#{value}\"", loud: false, blocking: false
|
25
26
|
else
|
@@ -28,7 +29,7 @@ module GitReflow
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def unset(key, value: nil, local: false)
|
31
|
-
value =
|
32
|
+
value = value.nil? ? '' : "\"#{value}\""
|
32
33
|
if local
|
33
34
|
GitReflow::Sandbox.run "git config --unset-all #{key} #{value}", loud: false, blocking: false
|
34
35
|
else
|
@@ -45,5 +46,13 @@ module GitReflow
|
|
45
46
|
GitReflow::Sandbox.run "git config -f #{CONFIG_FILE_PATH} --add #{key} \"#{value}\"", loud: false, blocking: false
|
46
47
|
end
|
47
48
|
end
|
49
|
+
|
50
|
+
def cached_git_config_value(key)
|
51
|
+
instance_variable_get(:"@#{key.tr('.-', '_')}").to_s
|
52
|
+
end
|
53
|
+
|
54
|
+
def cache_git_config_key(key, value)
|
55
|
+
instance_variable_set(:"@#{key.tr('.-', '_')}", value.to_s.strip)
|
56
|
+
end
|
48
57
|
end
|
49
58
|
end
|
@@ -1,51 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'git_reflow/config'
|
2
4
|
require 'git_reflow/sandbox'
|
3
5
|
|
4
6
|
module GitReflow
|
7
|
+
# Includes many helper methods for common tasks within a git repository.
|
5
8
|
module GitHelpers
|
6
9
|
include Sandbox
|
7
10
|
|
11
|
+
def default_editor
|
12
|
+
ENV['EDITOR'] || 'vi'
|
13
|
+
end
|
14
|
+
|
8
15
|
def git_root_dir
|
9
|
-
return @git_root_dir
|
16
|
+
return @git_root_dir unless @git_root_dir.to_s.empty?
|
10
17
|
@git_root_dir = run('git rev-parse --show-toplevel', loud: false).strip
|
11
18
|
end
|
12
19
|
|
13
20
|
def git_editor_command
|
14
|
-
git_editor =
|
15
|
-
if git_editor.
|
21
|
+
git_editor = GitReflow::Config.get('core.editor')
|
22
|
+
if !git_editor.empty?
|
16
23
|
git_editor
|
17
24
|
else
|
18
|
-
|
25
|
+
default_editor
|
19
26
|
end
|
20
27
|
end
|
21
28
|
|
22
29
|
def remote_user
|
23
|
-
return
|
30
|
+
return '' if GitReflow::Config.get('remote.origin.url').empty?
|
24
31
|
extract_remote_user_and_repo_from_remote_url(GitReflow::Config.get('remote.origin.url'))[:user]
|
25
32
|
end
|
26
33
|
|
27
34
|
def remote_repo_name
|
28
|
-
return
|
35
|
+
return '' if GitReflow::Config.get('remote.origin.url').empty?
|
29
36
|
extract_remote_user_and_repo_from_remote_url(GitReflow::Config.get('remote.origin.url'))[:repo]
|
30
37
|
end
|
31
38
|
|
39
|
+
def default_base_branch
|
40
|
+
base_branch_name = GitReflow::Config.get('reflow.base-branch')
|
41
|
+
return 'master' if base_branch_name.empty?
|
42
|
+
base_branch_name
|
43
|
+
end
|
44
|
+
|
32
45
|
def current_branch
|
33
46
|
run("git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g'", loud: false).strip
|
34
47
|
end
|
35
48
|
|
36
49
|
def pull_request_template
|
37
|
-
filenames_to_try = %w
|
38
|
-
|
39
|
-
|
40
|
-
|
50
|
+
filenames_to_try = %w[.github/PULL_REQUEST_TEMPLATE.md
|
51
|
+
.github/PULL_REQUEST_TEMPLATE
|
52
|
+
PULL_REQUEST_TEMPLATE.md
|
53
|
+
PULL_REQUEST_TEMPLATE].map do |file|
|
41
54
|
"#{git_root_dir}/#{file}"
|
42
55
|
end
|
43
56
|
|
44
|
-
|
45
|
-
|
57
|
+
parse_first_matching_template_file(filenames_to_try)
|
58
|
+
end
|
59
|
+
|
60
|
+
def merge_commit_template
|
61
|
+
filenames_to_try = %w[.github/MERGE_COMMIT_TEMPLATE.md
|
62
|
+
.github/MERGE_COMMIT_TEMPLATE
|
63
|
+
MERGE_COMMIT_TEMPLATE.md
|
64
|
+
MERGE_COMMIT_TEMPLATE].map do |file|
|
65
|
+
"#{git_root_dir}/#{file}"
|
46
66
|
end
|
47
67
|
|
48
|
-
|
68
|
+
parse_first_matching_template_file(filenames_to_try)
|
49
69
|
end
|
50
70
|
|
51
71
|
def get_first_commit_message
|
@@ -53,12 +73,12 @@ module GitReflow
|
|
53
73
|
end
|
54
74
|
|
55
75
|
def push_current_branch(options = {})
|
56
|
-
remote = options[:remote] ||
|
76
|
+
remote = options[:remote] || 'origin'
|
57
77
|
run_command_with_label "git push #{remote} #{current_branch}"
|
58
78
|
end
|
59
79
|
|
60
80
|
def update_current_branch(options = {})
|
61
|
-
remote = options[:remote] ||
|
81
|
+
remote = options[:remote] || 'origin'
|
62
82
|
run_command_with_label "git pull #{remote} #{current_branch}"
|
63
83
|
push_current_branch(options)
|
64
84
|
end
|
@@ -86,23 +106,50 @@ module GitReflow
|
|
86
106
|
run_command_with_label "git merge #{base_branch}"
|
87
107
|
end
|
88
108
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
|
109
|
+
def append_to_merge_commit_message(message = '', merge_method: "squash")
|
110
|
+
tmp_merge_message_path = "#{git_root_dir}/.git/tmp_merge_msg"
|
111
|
+
dest_merge_message_path = merge_message_path(merge_method: merge_method)
|
112
|
+
|
113
|
+
run "touch #{tmp_merge_message_path}"
|
114
|
+
|
115
|
+
File.open(tmp_merge_message_path, "w") do |file_content|
|
93
116
|
file_content.puts message
|
94
|
-
if File.exists?
|
95
|
-
File.foreach(
|
117
|
+
if File.exists? dest_merge_message_path
|
118
|
+
File.foreach(dest_merge_message_path) do |line|
|
96
119
|
file_content.puts line
|
97
120
|
end
|
98
121
|
end
|
99
122
|
end
|
100
123
|
|
101
|
-
run "mv #{
|
124
|
+
run "mv #{tmp_merge_message_path} #{dest_merge_message_path}"
|
125
|
+
end
|
126
|
+
|
127
|
+
def merge_message_path(merge_method: nil)
|
128
|
+
merge_method = merge_method || GitReflow::Config.get("reflow.merge-method")
|
129
|
+
merge_method = "squash" if "#{merge_method}".length < 1
|
130
|
+
if merge_method =~ /squash/i
|
131
|
+
"#{git_root_dir}/.git/SQUASH_MSG"
|
132
|
+
else
|
133
|
+
"#{git_root_dir}/.git/MERGE_MSG"
|
134
|
+
end
|
102
135
|
end
|
103
136
|
|
104
137
|
private
|
105
138
|
|
139
|
+
def parse_first_matching_template_file(template_file_names)
|
140
|
+
filename = template_file_names.detect do |file|
|
141
|
+
File.exist? file
|
142
|
+
end
|
143
|
+
|
144
|
+
# Thanks to @Shalmezad for contribuiting the template `gsub` snippet :-)
|
145
|
+
# https://github.com/reenhanced/gitreflow/issues/51#issuecomment-253535093
|
146
|
+
if filename
|
147
|
+
template_content = File.read filename
|
148
|
+
template_content.gsub!(/\{\{([a-zA-Z_]+[a-zA-Z0-9_]*)\}\}/) { GitReflow.public_send($1) }
|
149
|
+
template_content
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
106
153
|
def extract_remote_user_and_repo_from_remote_url(remote_url)
|
107
154
|
result = { user: '', repo: '' }
|
108
155
|
return result unless "#{remote_url}".length > 0
|