git_helper 1.3.1 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +17 -13
- data/README.md +42 -47
- data/Rakefile +1 -37
- data/bin/git-helper +10 -28
- data/lib/git_helper.rb +3 -5
- data/lib/git_helper/change_remote.rb +53 -40
- data/lib/git_helper/checkout_default.rb +1 -1
- data/lib/git_helper/clean_branches.rb +1 -4
- data/lib/git_helper/code_request.rb +95 -0
- data/lib/git_helper/empty_commit.rb +1 -1
- data/lib/git_helper/forget_local_commits.rb +7 -0
- data/lib/git_helper/git_config_reader.rb +1 -1
- data/lib/git_helper/gitlab_client.rb +0 -1
- data/lib/git_helper/highline_cli.rb +20 -15
- data/lib/git_helper/local_code.rb +75 -23
- data/lib/git_helper/merge_request.rb +45 -74
- data/lib/git_helper/new_branch.rb +2 -13
- data/lib/git_helper/octokit_client.rb +0 -1
- data/lib/git_helper/pull_request.rb +34 -69
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +173 -0
- data/spec/git_helper/checkout_default_spec.rb +19 -0
- data/spec/git_helper/clean_branches_spec.rb +19 -0
- data/spec/git_helper/code_request_spec.rb +259 -0
- data/spec/git_helper/empty_commit_spec.rb +19 -0
- data/spec/git_helper/forget_local_commits_spec.rb +19 -0
- data/spec/git_helper/git_config_reader_spec.rb +60 -0
- data/spec/git_helper/gitlab_client_spec.rb +26 -0
- data/spec/git_helper/highline_cli_spec.rb +215 -0
- data/spec/git_helper/local_code_spec.rb +232 -0
- data/spec/git_helper/merge_request_spec.rb +234 -0
- data/spec/git_helper/new_branch_spec.rb +44 -0
- data/spec/git_helper/octokit_client_spec.rb +26 -0
- data/spec/git_helper/pull_request_spec.rb +246 -0
- data/spec/spec_helper.rb +0 -7
- metadata +41 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34ec4f36cbe8b3cf3875894ee4670a5ca704ce4f67abeac7df2d5778f48a474f
|
4
|
+
data.tar.gz: 51721de128e9639c61c321ef0454c141cad5f91f4ec52ef5aa2161e6bb531c32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f2a22415758219d80055e4ebdb0b954f49bdfb27d2023badea8d0f45e2be151e16d0683c351fd1dd890f7ef864ee5e4291d545af369936e1d65ee0ff14195b4
|
7
|
+
data.tar.gz: e2bdae4669a0331f84ecc50c7f60b1af00e987556ec2644abbe4c0e44cd45185c16820f4d508c451ad4883adf4e19c4a5dac89670bb6b500c2a700ffd0214ac4
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
git_helper (
|
4
|
+
git_helper (3.0.0)
|
5
5
|
gitlab (~> 4.16)
|
6
6
|
gli (~> 2.13)
|
7
7
|
highline (~> 2.0)
|
@@ -61,18 +61,23 @@ GEM
|
|
61
61
|
coderay (~> 1.1)
|
62
62
|
method_source (~> 1.0)
|
63
63
|
public_suffix (4.0.6)
|
64
|
-
rake (
|
64
|
+
rake (13.0.1)
|
65
65
|
rb-fsevent (0.10.4)
|
66
66
|
rb-inotify (0.10.1)
|
67
67
|
ffi (~> 1.0)
|
68
|
-
rspec (
|
69
|
-
rspec-core (~>
|
70
|
-
rspec-expectations (~>
|
71
|
-
rspec-mocks (~>
|
72
|
-
rspec-core (
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
rspec (3.9.0)
|
69
|
+
rspec-core (~> 3.9.0)
|
70
|
+
rspec-expectations (~> 3.9.0)
|
71
|
+
rspec-mocks (~> 3.9.0)
|
72
|
+
rspec-core (3.9.3)
|
73
|
+
rspec-support (~> 3.9.3)
|
74
|
+
rspec-expectations (3.9.2)
|
75
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
+
rspec-support (~> 3.9.0)
|
77
|
+
rspec-mocks (3.9.1)
|
78
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
+
rspec-support (~> 3.9.0)
|
80
|
+
rspec-support (3.9.3)
|
76
81
|
sawyer (0.8.2)
|
77
82
|
addressable (>= 2.3.5)
|
78
83
|
faraday (> 0.8, < 2.0)
|
@@ -88,10 +93,9 @@ PLATFORMS
|
|
88
93
|
DEPENDENCIES
|
89
94
|
bundler (~> 2.1)
|
90
95
|
git_helper!
|
91
|
-
guard (~> 2.6)
|
92
96
|
guard-rspec (~> 4.3)
|
93
|
-
rake (~>
|
94
|
-
rspec (~>
|
97
|
+
rake (~> 13.0)
|
98
|
+
rspec (~> 3.9)
|
95
99
|
|
96
100
|
BUNDLED WITH
|
97
101
|
2.1.4
|
data/README.md
CHANGED
@@ -6,16 +6,18 @@
|
|
6
6
|
gem install git_helper
|
7
7
|
```
|
8
8
|
|
9
|
-
Some of the commands in this gem can be used without any additional configuration. However, others utilize special GitHub or GitLab configuration. To provide access tokens for this, create a `~/.
|
9
|
+
Some of the commands in this gem can be used without any additional configuration. However, others utilize special GitHub or GitLab configuration. To provide access tokens for this, create a `~/.git_helper/config.yml` file. The contents should look like this:
|
10
10
|
|
11
11
|
```
|
12
|
-
:github_user:
|
12
|
+
:github_user: GITHUB-USERNAME
|
13
13
|
:github_token: GITHUB-TOKEN
|
14
|
-
:gitlab_user:
|
14
|
+
:gitlab_user: GITLAB-USERNAME
|
15
15
|
:gitlab_token: GITLAB-TOKEN
|
16
16
|
```
|
17
17
|
|
18
|
-
To
|
18
|
+
To create or see what access tokens you have, look [here for GitHub personal access tokens](https://github.com/settings/tokens) and [here for GitLab access tokens](https://gitlab.com/profile/personal_access_tokens). You could either have one set of tokens for each computer you use, or just have one set of tokens for all computers that you rotate periodically.
|
19
|
+
|
20
|
+
Once the gem is installed, run this to view the help screen:
|
19
21
|
```bash
|
20
22
|
git-helper --help
|
21
23
|
```
|
@@ -30,15 +32,22 @@ git-helper --version
|
|
30
32
|
As an additional option, you can set each of the following commands to be a git plugin, meaning you can call them in a way that feels even more git-native:
|
31
33
|
|
32
34
|
```bash
|
33
|
-
# As a Gem
|
34
|
-
git-helper clean-branches
|
35
|
-
git-helper
|
35
|
+
# As a Gem # As a Plugin
|
36
|
+
git-helper clean-branches git clean-branches
|
37
|
+
git-helper code-request --create git code-request --create
|
38
|
+
```
|
39
|
+
|
40
|
+
To do this, download the `plugins.zip` file in the root of this directory. Unzip and place the contents in the appropriate location:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
mkdir ~/.git_helper
|
44
|
+
unzip path/to/downloaded/plugins.zip -d ~/.git_helper
|
36
45
|
```
|
37
46
|
|
38
|
-
|
47
|
+
Now, the plugins will live in `~/.git_helper/plugins/*`. Add the following line to your `~/.bash_profile`:
|
39
48
|
|
40
49
|
```
|
41
|
-
export PATH=/
|
50
|
+
export PATH=/path/to/computer/home/.git_helper/plugins:$PATH
|
42
51
|
```
|
43
52
|
|
44
53
|
And then run `source ~/.bash_profile`.
|
@@ -71,7 +80,7 @@ If you're going to make using git workflows easier, might as well provide lots o
|
|
71
80
|
|
72
81
|
This can be used when switching the owners of a GitHub repo. When you switch a username, GitHub only makes some changes for you. With this command, you no longer have to manually walk through local repo and switch the remotes from each one into a remote with the new username.
|
73
82
|
|
74
|
-
This command will go through every directory in a directory, see if it is a git directory
|
83
|
+
This command will go through every directory in a directory, and see if it is a git directory. It will then ask the user if they wish to process the git directory in question. The command does not yet know if there's any changes to be made. If the user says 'yes', then it will check to see if the old username is included in the remote URL of that git directory. If it is, then the command will change the remote URL to instead point to the new username's remote URL. To run the command, run:
|
75
84
|
|
76
85
|
```bash
|
77
86
|
git-helper change-remote OLD-OWNER NEW-OWNER
|
@@ -93,75 +102,61 @@ git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/CORRECT-DEFAULT-BR
|
|
93
102
|
|
94
103
|
### `clean-branches`
|
95
104
|
|
96
|
-
This command will bring you to the repository's default branch, `git pull`, `git fetch -p`, and will clean up your local branches on your machine by seeing which ones are existing on the remote, and updating yours accordingly. To run:
|
105
|
+
This command will bring you to the repository's default branch, `git pull`, `git fetch -p`, and will clean up your local branches on your machine by seeing which ones are existing on the remote, and updating yours accordingly. To clean your local branches, run:
|
97
106
|
|
98
107
|
```bash
|
99
108
|
git-helper clean-branches
|
100
109
|
```
|
101
110
|
|
102
|
-
### `
|
103
|
-
|
104
|
-
For some reason, I'm always forgetting the commands to create an empty commit. So with this command, it becomes easy. The commit message of this commit will be `'Empty commit'`. To run the command, run:
|
105
|
-
|
106
|
-
```bash
|
107
|
-
git-helper empty-commit
|
108
|
-
```
|
109
|
-
|
110
|
-
### `merge-request`
|
111
|
+
### `code-request`
|
111
112
|
|
112
|
-
This command can be used to handily make new GitLab merge requests and to
|
113
|
+
This command can be used to handily make new GitHub/GitLab pull/merge requests and to merge those requests from the command line. The command uses either the [`Octokit::Client`](https://octokit.github.io/octokit.rb/Octokit/Client.html) or [`Gitlab` client](https://github.com/NARKOZ/gitlab) to do this, so make sure you have a `~/.git_helper/config.yml` file set up in the home directory of your computer. For instructions on how to do that, see [Gem Usage](#gem-usage).
|
113
114
|
|
114
|
-
After setup is complete, you can call the file, and send in a flag indicating whether to create a
|
115
|
+
After setup is complete, you can call the file, and send in a flag indicating whether to create a code request, `-c`, or to merge a code request, `-m`.
|
115
116
|
|
116
117
|
```bash
|
117
|
-
git-helper
|
118
|
+
git-helper code-request -c
|
118
119
|
# OR
|
119
|
-
git-helper
|
120
|
+
git-helper code-request -m
|
120
121
|
```
|
121
122
|
|
122
|
-
If you're trying to create a
|
123
|
+
If you're trying to create a code request, the command will provide an autogenerated code request title based on your branch name. It will separate the branch name by `'_'` if underscores are in the branch, or `'-'` if dashes are present. Then it will join the list of words together by spaces. If there's a pattern in the form of `jira-123` or `jira_123` in the first part of the branch name, then it'll add `JIRA-123` to the first part of the code request. You can respond 'yes' or 'no'. If you respond 'no', you can provide your own code request title.
|
123
124
|
|
124
125
|
The command will also ask you if the default branch of the repository is the proper base branch to use. You can say 'yes' or 'no'. If you respond 'no', then you can give the command your chosen base base.
|
125
126
|
|
126
|
-
Lastly, it'll ask the user to apply any
|
127
|
+
Lastly, for GitHub, it'll ask the user to apply any pull request templates found at `.github/pull_request_template.md`, `./pull_request_template.md`, or `.github/PULL_REQUEST_TEMPLATE/*.md`. Applying any template is optional, and a user can make an empty pull request if they desire. For GitLab, it'll ask the user to apply any merge request templates found at any `.gitlab/merge_request_template.md`, `./merge_request_template.md`, or `.gitlab/merge_request_templates/*.md`. Applying any template is optional, and from the command's standpoint, a user can make an empty merge request if they desire (although GitLab may still add a merge request template if the project itself requires one). When searching for templates, the code ignores cases, so the file could be named with all capital letters or all lowercase letters.
|
127
128
|
|
128
|
-
If you're requesting to merge a
|
129
|
+
If you're requesting to merge a code request, the command will ask you the number ID of the code request you wish to merge. For GitHub, the command will also ask you what type of merge to do: regular merging, squashing, or rebasing. The commit message to use during the merge/squash/rebase will be the title of the pull request. For GitLab, the command will also ask you what type of merge to do: regular merging or squashing. The commit message to use during the merge/squash will be the title of the merge request.
|
129
130
|
|
130
131
|
If you're getting stuck, you can run the command with a `--help` flag instead, to get some more information.
|
131
132
|
|
132
|
-
### `
|
133
|
+
### `empty-commit`
|
133
134
|
|
134
|
-
|
135
|
+
For some reason, I'm always forgetting the commands to create an empty commit. So with this command, it becomes easy. The commit message of this commit will be `'Empty commit'`. To run the command, run:
|
135
136
|
|
136
137
|
```bash
|
137
|
-
git-helper
|
138
|
-
# OR
|
139
|
-
git-helper new-branch NEW_BRANCH_NAME
|
138
|
+
git-helper empty-commit
|
140
139
|
```
|
141
140
|
|
142
|
-
|
143
|
-
|
144
|
-
### `pull-request`
|
141
|
+
### `forget-local-commits`
|
145
142
|
|
146
|
-
This command
|
147
|
-
|
148
|
-
After setup is complete, you can call the file, and send in a flag indicating whether to create a pull request, `-c`, or to merge a pull request, `-m`.
|
143
|
+
This command is handy if you locally have a bunch of commits you wish to completely get rid of. This command basically does a hard reset to `origin/HEAD`. Once you forget them, they're completely gone, so run carefully. To test it out, run:
|
149
144
|
|
150
145
|
```bash
|
151
|
-
git-helper
|
152
|
-
# OR
|
153
|
-
git-helper pull-request -m
|
146
|
+
git-helper forget-local-commits
|
154
147
|
```
|
155
148
|
|
156
|
-
|
157
|
-
|
158
|
-
The command will also ask you if the default branch of the repository is the proper base branch to use. You can say 'yes' or 'no'. If you respond 'no', then you can give the command your chosen base base.
|
149
|
+
### `new-branch`
|
159
150
|
|
160
|
-
|
151
|
+
This command is useful for making new branches in a repository on the command line. To run the command, run:
|
161
152
|
|
162
|
-
|
153
|
+
```bash
|
154
|
+
git-helper new-branch
|
155
|
+
# OR
|
156
|
+
git-helper new-branch NEW_BRANCH_NAME
|
157
|
+
```
|
163
158
|
|
164
|
-
|
159
|
+
The command either accepts a branch name right away or it will ask you for the name of your new branch. Make sure your input does not contain any spaces or special characters.
|
165
160
|
|
166
161
|
## Contributing
|
167
162
|
|
data/Rakefile
CHANGED
@@ -1,37 +1 @@
|
|
1
|
-
|
2
|
-
begin
|
3
|
-
require 'bundler/setup'
|
4
|
-
rescue LoadError
|
5
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'rdoc/task'
|
9
|
-
rescue LoadError
|
10
|
-
require 'rdoc/rdoc'
|
11
|
-
require 'rake/rdoctask'
|
12
|
-
RDoc::Task = Rake::RDocTask
|
13
|
-
end
|
14
|
-
|
15
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
-
rdoc.rdoc_dir = 'rdoc'
|
17
|
-
rdoc.title = 'Hubstats'
|
18
|
-
rdoc.options << '--line-numbers'
|
19
|
-
rdoc.rdoc_files.include('README.rdoc')
|
20
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
-
end
|
22
|
-
|
23
|
-
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
-
load 'rails/tasks/engine.rake'
|
25
|
-
|
26
|
-
Bundler::GemHelper.install_tasks
|
27
|
-
|
28
|
-
require 'rake/testtask'
|
29
|
-
|
30
|
-
Rake::TestTask.new(:test) do |t|
|
31
|
-
t.libs << 'lib'
|
32
|
-
t.libs << 'test'
|
33
|
-
t.pattern = 'test/**/*_test.rb'
|
34
|
-
t.verbose = false
|
35
|
-
end
|
36
|
-
|
37
|
-
task :default => :test
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/git-helper
CHANGED
@@ -22,16 +22,14 @@ arg :new_owner
|
|
22
22
|
desc "Update a repository's remote URLs from an old GitHub owner to a new owner."
|
23
23
|
command 'change-remote' do |c|
|
24
24
|
c.action do |global_options, options, args|
|
25
|
-
require_relative '../lib/git_helper/change_remote.rb'
|
26
25
|
raise ArgumentError, 'You must specify an old owner and a new owner' unless args.count == 2
|
27
|
-
GitHelper::ChangeRemote.new
|
26
|
+
GitHelper::ChangeRemote.new(args[0], args[1]).execute
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
30
|
desc "Checks out the default branch of a repo based on the local remote branches."
|
32
31
|
command 'checkout-default' do |c|
|
33
32
|
c.action do |global_options, options, args|
|
34
|
-
require_relative '../lib/git_helper/checkout_default.rb'
|
35
33
|
GitHelper::CheckoutDefault.new.execute
|
36
34
|
end
|
37
35
|
end
|
@@ -39,7 +37,6 @@ end
|
|
39
37
|
desc "Clean a repository's git branches."
|
40
38
|
command 'clean-branches' do |c|
|
41
39
|
c.action do |global_options, options, args|
|
42
|
-
require_relative '../lib/git_helper/clean_branches.rb'
|
43
40
|
GitHelper::CleanBranches.new.execute
|
44
41
|
end
|
45
42
|
end
|
@@ -47,27 +44,14 @@ end
|
|
47
44
|
desc "Creates an empty commit with a basic commit message."
|
48
45
|
command 'empty-commit' do |c|
|
49
46
|
c.action do |global_options, options, args|
|
50
|
-
require_relative '../lib/git_helper/empty_commit.rb'
|
51
47
|
GitHelper::EmptyCommit.new.execute
|
52
48
|
end
|
53
49
|
end
|
54
50
|
|
55
|
-
desc
|
56
|
-
command '
|
57
|
-
c.switch [:c, :create], desc: 'Create a new pull request'
|
58
|
-
c.switch [:m, :merge], desc: 'Merge an existing pull request'
|
59
|
-
|
51
|
+
desc "Reset your local git commits to origin/HEAD."
|
52
|
+
command 'forget-local-commits' do |c|
|
60
53
|
c.action do |global_options, options, args|
|
61
|
-
|
62
|
-
raise ArgumentError, "You must specify an action (either '-m'/'--merge' or '-c'/'--create')" unless options[:create] || options[:merge]
|
63
|
-
|
64
|
-
options = global_options.merge(options)
|
65
|
-
|
66
|
-
if options[:create]
|
67
|
-
GitHelper::GitLabMergeRequest.new.create
|
68
|
-
elsif options[:merge]
|
69
|
-
GitHelper::GitLabMergeRequest.new.merge
|
70
|
-
end
|
54
|
+
GitHelper::ForgetLocalCommits.new.execute
|
71
55
|
end
|
72
56
|
end
|
73
57
|
|
@@ -75,26 +59,24 @@ arg :new_branch_name, optional: true
|
|
75
59
|
desc 'Create a new branch for features, bug fixes, or experimentation.'
|
76
60
|
command 'new-branch' do |c|
|
77
61
|
c.action do |global_options, options, args|
|
78
|
-
require_relative '../lib/git_helper/new_branch.rb'
|
79
62
|
GitHelper::NewBranch.new.execute(args[0])
|
80
63
|
end
|
81
64
|
end
|
82
65
|
|
83
|
-
desc 'Create a GitHub pull request from the current branch.'
|
84
|
-
command '
|
85
|
-
c.switch [:c, :create], desc: 'Create a new pull request'
|
86
|
-
c.switch [:m, :merge], desc: 'Merge an existing pull request'
|
66
|
+
desc 'Create or merge a GitHub or GitLab pull/merge request from the current branch. The command will figure out whether your code project belongs to GitHub or GitLab'
|
67
|
+
command 'code-request' do |c|
|
68
|
+
c.switch [:c, :create], desc: 'Create a new pull/merge request'
|
69
|
+
c.switch [:m, :merge], desc: 'Merge an existing pull/merge request'
|
87
70
|
|
88
71
|
c.action do |global_options, options, args|
|
89
|
-
require_relative '../lib/git_helper/pull_request.rb'
|
90
72
|
raise ArgumentError, "You must specify an action (either '-m'/'--merge' or '-c'/'--create')" unless options[:create] || options[:merge]
|
91
73
|
|
92
74
|
options = global_options.merge(options)
|
93
75
|
|
94
76
|
if options[:create]
|
95
|
-
GitHelper::
|
77
|
+
GitHelper::CodeRequest.new.create
|
96
78
|
elsif options[:merge]
|
97
|
-
GitHelper::
|
79
|
+
GitHelper::CodeRequest.new.merge
|
98
80
|
end
|
99
81
|
end
|
100
82
|
end
|
data/lib/git_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'octokit'
|
5
|
-
require_relative 'git_helper/version'
|
1
|
+
Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'git_helper')) + "/**/*.rb"].each do |file|
|
2
|
+
require_relative file
|
3
|
+
end
|
6
4
|
|
7
5
|
module GitHelper; end
|
@@ -1,55 +1,68 @@
|
|
1
1
|
module GitHelper
|
2
2
|
class ChangeRemote
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
attr_accessor :old_owner, :new_owner
|
4
|
+
|
5
|
+
def initialize(old_owner, new_owner)
|
6
|
+
@old_owner = old_owner
|
7
|
+
@new_owner = new_owner
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
original_dir = Dir.pwd
|
12
|
+
nested_dirs = Dir.entries(original_dir).select do |entry|
|
13
|
+
entry_dir = File.join(original_dir, entry)
|
7
14
|
File.directory?(entry_dir) && !(entry == '.' || entry == '..')
|
8
15
|
end
|
9
16
|
|
10
|
-
nested_dirs.each do |
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
else
|
21
|
-
puts " No need to update remote."
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
Dir.chdir current_dir
|
17
|
+
nested_dirs.each do |nested_dir|
|
18
|
+
process_dir(nested_dir, original_dir)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private def process_dir(current_dir, original_dir)
|
23
|
+
Dir.chdir(current_dir)
|
24
|
+
|
25
|
+
if File.exist?('.git')
|
26
|
+
process_git_repository if cli.process_directory_remotes?(current_dir)
|
26
27
|
end
|
28
|
+
|
29
|
+
Dir.chdir(original_dir)
|
27
30
|
end
|
28
31
|
|
29
|
-
private def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
puts " Done."
|
37
|
-
rescue Exception => e
|
38
|
-
puts " Could not complete: #{e.message}"
|
32
|
+
private def process_git_repository
|
33
|
+
local_code.remotes.each do |remote|
|
34
|
+
if remote.include?(old_owner)
|
35
|
+
process_remote(remote)
|
36
|
+
else
|
37
|
+
puts " Found remote is not pointing to #{old_owner}."
|
38
|
+
end
|
39
39
|
end
|
40
|
+
puts "\n"
|
40
41
|
end
|
41
42
|
|
42
|
-
private def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
private def process_remote(remote)
|
44
|
+
remote_name = local_code.remote_name(remote)
|
45
|
+
|
46
|
+
if local_code.ssh_remote?(remote)
|
47
|
+
repo = local_code.remote_project(remote)
|
48
|
+
source_name = local_code.remote_source(remote)
|
49
|
+
remote_url = "git@#{source_name}:#{new_owner}/#{repo}.git"
|
50
|
+
elsif local_code.https_remote?(remote)
|
51
|
+
repo = local_code.remote_project(remote)
|
52
|
+
source_name = local_code.remote_source(remote)
|
53
|
+
remote_url = "https://#{source_name}/#{new_owner}/#{repo}.git"
|
52
54
|
end
|
55
|
+
|
56
|
+
puts " Changing the remote URL #{remote_name} to be '#{remote_url}'."
|
57
|
+
local_code.change_remote(remote_name, remote_url)
|
58
|
+
end
|
59
|
+
|
60
|
+
private def local_code
|
61
|
+
@local_code ||= GitHelper::LocalCode.new
|
62
|
+
end
|
63
|
+
|
64
|
+
private def cli
|
65
|
+
@cli ||= GitHelper::HighlineCli.new
|
53
66
|
end
|
54
67
|
end
|
55
68
|
end
|