git-utils 2.1.0 → 2.2.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/README.md +15 -15
- data/bin/git-cleanup +4 -4
- data/lib/git-utils/command.rb +22 -1
- data/lib/git-utils/merge_branch.rb +2 -2
- data/lib/git-utils/sync.rb +2 -2
- data/lib/git-utils/sync_fork.rb +3 -3
- data/lib/git-utils/version.rb +1 -1
- data/spec/commands/merge_branch_spec.rb +16 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e1c46d3c400bbc8d913745063c92a103b45b11e59cdd2bb494a099100b12d05
|
4
|
+
data.tar.gz: b2d4253cc25ec916282f1bfd9198f3017d6369bc55deb41b3a0161fb52bbd34c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bff26db7b631b266ba97210256544ca7031efb99e4af1f9289414598c343d8f9762421e386921c58d3c00ad93a5bc03d7eed2e3e60dcc5b26d9f5411d71aee3a
|
7
|
+
data.tar.gz: 5ba1d70da71ae6b35afa1fa1dd7e8ceb36b2db348587b9a7adb910fc084f5a4933aefba765f2d0b9db2e96975083dcea99f99b9de74efd6c1472eb6e75fdfa34
|
data/README.md
CHANGED
@@ -2,27 +2,27 @@
|
|
2
2
|
|
3
3
|
This repo contains some Git utility scripts. The highlights are `git open`, `git pull-request`, `git push-branch`, and `git undo`, which you’ll never understand how you did without.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
The `git-utils` used to be pure Bash scripts, but they are now available as a Ruby gem, both because Ruby is more powerful than bash and because now `git-utils` can be included more easily as a dependency for the [pivotal-github](https://github.com/mhartl/pivotal-github/) gem. As a result, installation is easy if you have RubyGems installed:
|
5
|
+
`git-utils` used to be pure Bash scripts, but they are now available as a Ruby gem:
|
8
6
|
|
9
7
|
gem install git-utils
|
10
8
|
|
9
|
+
See below for more details on the commands defined by `git-utils`. To learn more about how to use Git itself, see the tutorial book and online course [*Learn Enough Git to Be Dangerous*](https://www.learnenough.com/git).
|
10
|
+
|
11
11
|
## Commands
|
12
12
|
|
13
13
|
* `git amend`: alias for `git commit --amend`
|
14
14
|
* `git bump`: makes a commit with the message `"Bump version number"`
|
15
|
-
* `git cleanup`: deletes every branch already merged into current branch (apart from `master`, `staging`, `development`, and any branches listed in `~/.git-cleanup-preserved`). Pass the `-r` option to delete remote merged branches.
|
16
|
-
* `git merge-into-branch [branch]`: merges current branch into given branch (defaults to
|
15
|
+
* `git cleanup`: deletes every branch already merged into current branch (apart from `master`, `main`, `staging`, `development`, and any branches listed in `~/.git-cleanup-preserved`). Pass the `-r` option to delete remote merged branches.
|
16
|
+
* `git merge-into-branch [branch]`: merges current branch into given branch (defaults to repo's default branch)
|
17
17
|
* `git minor`: makes a commit with the message `"Make minor changes"`
|
18
|
-
* `git open`: opens the remote page for the repo (
|
18
|
+
* `git open`: opens the remote page for the repo (macOS & Linux)
|
19
19
|
* `git polish`: makes a commit with the message `"Polish"`
|
20
|
-
* `git pull-request`: pushes the branch and opens the remote page for issuing a new a pull request (
|
20
|
+
* `git pull-request`: pushes the branch and opens the remote page for issuing a new a pull request (macOS-only)
|
21
21
|
* `git push-branch`: pushes the current branch up to origin
|
22
22
|
* `git delete-remote-branch <branch>`: deletes the remote branch if it is safe to do so
|
23
23
|
* `git switch <pattern>`: switches to the first branch matching the given pattern
|
24
|
-
* `git sync [branch]`: syncs the given branch with the remote branch (defaults to
|
25
|
-
* `git sync-fork`: syncs the
|
24
|
+
* `git sync [branch]`: syncs the given branch with the remote branch (defaults to repo's default branch)
|
25
|
+
* `git sync-fork`: syncs the default branch of a fork with the original upstream default (assumes upstream configuration as in “[Configuring a remote for a fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/configuring-a-remote-for-a-fork)”)
|
26
26
|
* `git typo`: makes a commit with the message `"Fix typo"`
|
27
27
|
* `git undo`: undoes the last commit
|
28
28
|
* `git graph`: displays full repository history in graphical format; alias for `git log --graph --oneline --decorate --all --full-history --author-date-order --no-notes`
|
@@ -41,12 +41,12 @@ Some of these commands deserve further explanation.
|
|
41
41
|
|
42
42
|
### git merge-into-branch
|
43
43
|
|
44
|
-
`git merge-into-branch [target]` merges the current branch into the target branch (defaults to
|
44
|
+
`git merge-into-branch [target]` merges the current branch into the target branch (defaults to repo's default branch). On a branch called `add-markdown-support` in a repo with default branch `main`, `git merge-into-branch` is equivalent to the following:
|
45
45
|
|
46
|
-
$ git checkout
|
46
|
+
$ git checkout main
|
47
47
|
$ git merge --no-ff --log add-markdown-support
|
48
48
|
|
49
|
-
Note that this effectively changes the default merge behavior from fast-forward to no-fast-forward, which makes it possible to use `git log` to see which of the commit objects together have implemented a feature on a particular branch. As noted in [A successful Git branching model](http://nvie.com/posts/a-successful-git-branching-model/)
|
49
|
+
Note that this effectively changes the default merge behavior from fast-forward to no-fast-forward, which makes it possible to use `git log` to see which of the commit objects together have implemented a feature on a particular branch. As noted in [A successful Git branching model](http://nvie.com/posts/a-successful-git-branching-model/):
|
50
50
|
|
51
51
|
> The `--no-ff` flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature… Yes, it will create a few more (empty) commit objects, but the gain is much bigger than that cost.
|
52
52
|
|
@@ -66,16 +66,16 @@ These options can be overriden (and thus restored to their defaults) by passing
|
|
66
66
|
|
67
67
|
### git sync
|
68
68
|
|
69
|
-
`git sync [branch]` syncs the given local branch with the remote branch (defaults to
|
69
|
+
`git sync [branch]` syncs the given local branch with the remote branch (defaults to repo's default branch). On a branch called `add-markdown-support` in a repo with default branch `master`, `git sync` is equivalent to the following:
|
70
70
|
|
71
71
|
$ git checkout master
|
72
72
|
$ git pull
|
73
73
|
$ git checkout add-markdown-support
|
74
74
|
|
75
|
-
The main purpose of `git sync` is to prepare the current branch for merging with
|
75
|
+
The main purpose of `git sync` is to prepare the current branch for merging with the default branch:
|
76
76
|
|
77
77
|
$ git sync
|
78
|
-
$ git merge master
|
78
|
+
$ git merge master # or `main`, etc.
|
79
79
|
|
80
80
|
(This is essentially equivalent to
|
81
81
|
|
data/bin/git-cleanup
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
require 'optparse'
|
3
3
|
|
4
4
|
# Deletes (almost) every branch already merged into current branch.
|
5
|
-
# Exceptions are `master`, `staging`, and `development`,
|
6
|
-
# branch, which are preserved.
|
7
|
-
# `~/.git-cleanup-preserved` file.
|
5
|
+
# Exceptions are `master`, `main`, `staging`, and `development`,
|
6
|
+
# and the current branch, which are preserved.
|
7
|
+
# We also support custom configuration via the `~/.git-cleanup-preserved` file.
|
8
8
|
|
9
9
|
options = {}
|
10
10
|
OptionParser.new do |opts|
|
@@ -15,7 +15,7 @@ OptionParser.new do |opts|
|
|
15
15
|
end
|
16
16
|
end.parse!
|
17
17
|
|
18
|
-
preserved = "master|staging|development"
|
18
|
+
preserved = "master|main|staging|development"
|
19
19
|
preserved_file = File.join(Dir.home, '.git-cleanup-preserved')
|
20
20
|
if File.exist?(preserved_file)
|
21
21
|
additional_preserved = File.read(preserved_file).strip.split("\n")
|
data/lib/git-utils/command.rb
CHANGED
@@ -26,6 +26,27 @@ class Command
|
|
26
26
|
@current_branch ||= `git rev-parse --abbrev-ref HEAD`.strip
|
27
27
|
end
|
28
28
|
|
29
|
+
# Returns the default branch for the current repository.
|
30
|
+
# Command retrieved from
|
31
|
+
# https://stackoverflow.com/questions/28666357/git-how-to-get-default-branch
|
32
|
+
def default_branch
|
33
|
+
branch_name = `git symbolic-ref --short refs/remotes/origin/HEAD \
|
34
|
+
| sed 's@^origin/@@'`.strip
|
35
|
+
if branch_name.empty?
|
36
|
+
$stderr.puts "Repository configuration error"
|
37
|
+
$stderr.puts "Missing reference to refs/remotes/origin/HEAD"
|
38
|
+
$stderr.puts "Run"
|
39
|
+
$stderr.puts
|
40
|
+
$stderr.puts " git remote set-head origin <default branch>"
|
41
|
+
$stderr.puts
|
42
|
+
$stderr.puts "where <default branch> is the default branch name"
|
43
|
+
$stderr.puts "(typically `main`, `master`, or `trunk`)"
|
44
|
+
$stderr.puts "and then rerun the command"
|
45
|
+
exit(1)
|
46
|
+
end
|
47
|
+
@default_branch ||= branch_name
|
48
|
+
end
|
49
|
+
|
29
50
|
# Returns the URL for the remote origin.
|
30
51
|
def origin_url
|
31
52
|
@origin_url ||= `git config --get remote.origin.url`.strip
|
@@ -95,4 +116,4 @@ class Command
|
|
95
116
|
def deliver?
|
96
117
|
options.deliver
|
97
118
|
end
|
98
|
-
end
|
119
|
+
end
|
@@ -28,8 +28,8 @@ class MergeBranch < Command
|
|
28
28
|
|
29
29
|
# Returns the name of the branch to be merged into.
|
30
30
|
# If there is anything left in the known options after parsing,
|
31
|
-
# that's the merge branch. Otherwise, it's
|
31
|
+
# that's the merge branch. Otherwise, it's the default branch.
|
32
32
|
def target_branch
|
33
|
-
self.known_options.first ||
|
33
|
+
self.known_options.first || default_branch
|
34
34
|
end
|
35
35
|
end
|
data/lib/git-utils/sync.rb
CHANGED
@@ -13,10 +13,10 @@ class Sync < Command
|
|
13
13
|
|
14
14
|
# Returns a command appropriate for executing at the command line.
|
15
15
|
def cmd
|
16
|
-
branch = self.known_options.first ||
|
16
|
+
branch = self.known_options.first || default_branch
|
17
17
|
c = ["git checkout #{branch}"]
|
18
18
|
c << "git pull"
|
19
19
|
c << "git checkout #{current_branch}"
|
20
20
|
c.join("\n")
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
data/lib/git-utils/sync_fork.rb
CHANGED
@@ -4,7 +4,7 @@ class SyncFork < Command
|
|
4
4
|
|
5
5
|
def parser
|
6
6
|
OptionParser.new do |opts|
|
7
|
-
opts.banner = "Usage: git sync-fork"
|
7
|
+
opts.banner = "Usage: git sync-fork [default]"
|
8
8
|
opts.on_tail("-h", "--help", "this usage guide") do
|
9
9
|
puts opts.to_s; exit 0
|
10
10
|
end
|
@@ -13,9 +13,9 @@ class SyncFork < Command
|
|
13
13
|
|
14
14
|
# Returns a command appropriate for executing at the command line.
|
15
15
|
def cmd
|
16
|
-
c = ["git checkout
|
16
|
+
c = ["git checkout #{default_branch}"]
|
17
17
|
c << "git fetch upstream"
|
18
|
-
c << "git merge upstream
|
18
|
+
c << "git merge upstream/#{default_branch}"
|
19
19
|
c.join("\n")
|
20
20
|
end
|
21
21
|
end
|
data/lib/git-utils/version.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe MergeBranch do
|
4
4
|
|
5
5
|
let(:command) { MergeBranch.new }
|
6
|
-
before
|
6
|
+
before { command.stub(:current_branch).and_return('tau-manifesto') }
|
7
7
|
subject { command }
|
8
8
|
|
9
9
|
its(:cmd) { should match /git merge/ }
|
@@ -19,6 +19,21 @@ describe MergeBranch do
|
|
19
19
|
its(:cmd) { should match /git checkout master/ }
|
20
20
|
end
|
21
21
|
|
22
|
+
describe "default branch" do
|
23
|
+
let(:command) { MergeBranch.new }
|
24
|
+
|
25
|
+
describe "for current real repo" do
|
26
|
+
subject { command.default_branch }
|
27
|
+
it { should match 'master' }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "for repo with different default" do
|
31
|
+
before { command.stub(:default_branch).and_return('main') }
|
32
|
+
subject { command.default_branch }
|
33
|
+
it { should match 'main' }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
22
37
|
describe "with a custom development branch" do
|
23
38
|
let(:command) { MergeBranch.new(['development']) }
|
24
39
|
its(:cmd) { should match /git checkout development/ }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Hartl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Add some Git utilities
|
14
14
|
email:
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
|
-
rubygems_version: 3.1.
|
104
|
+
rubygems_version: 3.1.4
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: See the README for full documentation
|