git-utils 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ff6ac2207f071e41328576590172fe7dc6f8721c
4
- data.tar.gz: e34ce04c025afcd6bc0382e8a9c7c28b4cfa52d3
2
+ SHA256:
3
+ metadata.gz: 3e1c46d3c400bbc8d913745063c92a103b45b11e59cdd2bb494a099100b12d05
4
+ data.tar.gz: b2d4253cc25ec916282f1bfd9198f3017d6369bc55deb41b3a0161fb52bbd34c
5
5
  SHA512:
6
- metadata.gz: 57314c2b35a311cb40e289595bb9dfa0232941ffa38700ce9442e39ed5e4190f5310c6d3e16dad38a9c8411744e07be746b744cf5464bdd1fce38114578de7fa
7
- data.tar.gz: 2d0bb6d0ebec487eea8f45f7ff973b3333226f7e6d03e5654c067e6ab03402bf878e23822e15ff7962b62ec76ca8291fdf9f42a99bec6eee162d95a201c7c910
6
+ metadata.gz: bff26db7b631b266ba97210256544ca7031efb99e4af1f9289414598c343d8f9762421e386921c58d3c00ad93a5bc03d7eed2e3e60dcc5b26d9f5411d71aee3a
7
+ data.tar.gz: 5ba1d70da71ae6b35afa1fa1dd7e8ceb36b2db348587b9a7adb910fc084f5a4933aefba765f2d0b9db2e96975083dcea99f99b9de74efd6c1472eb6e75fdfa34
data/README.md CHANGED
@@ -1,62 +1,64 @@
1
1
  # Git utilities
2
2
 
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.
3
+ This repo contains some Git utility scripts. The highlights are `git open`, `git pull-request`, `git push-branch`, and `git undo`, which youll never understand how you did without.
4
4
 
5
- The commands are especially useful when combined with [pivotal-github](https://github.com/mhartl/pivotal-github) gem (which, despite its name, also works with Bitbucket).
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
- * `git anal` (*use with caution*): makes a commit with the message "Make anal changes"
15
- * `git bump`: makes a commit with the message "Bump version number"
16
- * `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.
17
- * `git merge-branch [branch]`: merges current branch into given branch (defaults to `master`)
18
- * `git open`: opens the remote page for the repo (OS X & Linux)
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 (OS X only)
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`, `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
+ * `git minor`: makes a commit with the message `"Make minor changes"`
18
+ * `git open`: opens the remote page for the repo (macOS & Linux)
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 (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 master)
25
- * `git typo`: makes a commit with the message "Fix typo"
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
+ * `git typo`: makes a commit with the message `"Fix typo"`
26
27
  * `git undo`: undoes the last commit
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`
27
29
 
28
30
  ## Aliases
29
31
 
30
32
  Here are some suggested aliases:
31
33
 
32
- git config --global alias.mb merge-branch
33
- git config --global alias.pr pull-request
34
- git config --global alias.pb push-branch
34
+ git config --global alias.mib merge-into-branch
35
+ git config --global alias.pr pull-request
36
+ git config --global alias.pb push-branch
35
37
 
36
38
  ## Further details
37
39
 
38
40
  Some of these commands deserve further explanation.
39
41
 
40
- ### git merge-branch
42
+ ### git merge-into-branch
41
43
 
42
- `git merge-branch [target]` merges the current branch into the target branch (defaults to `master`). On a branch called `add-markdown-support`, `git merge-branch` is equivalent to the following:
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:
43
45
 
44
- $ git checkout master
46
+ $ git checkout main
45
47
  $ git merge --no-ff --log add-markdown-support
46
48
 
47
- 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/):
48
50
 
49
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.
50
52
 
51
53
  In addition, the `--log` option puts the commit messages from the individual commits in the merge message, which is especially useful for viewing the full diff represented by the commit.
52
54
 
53
- These options can be overriden (and thus restored to their defaults) by passing the options `-ff` or `--no-log`. `git merge-branch` accepts any options valid for `git merge`.
55
+ These options can be overriden (and thus restored to their defaults) by passing the options `-ff` or `--no-log`. `git merge-into-branch` accepts any options valid for `git merge`.
54
56
 
55
57
  ### git push-branch
56
58
 
57
59
  `git push-branch` creates a remote branch at `origin` with the name of the current branch:
58
60
 
59
- $ git branch-push
61
+ $ git push-branch
60
62
  * [new branch] add-markdown-support -> add-markdown-support
61
63
 
62
64
  `git push-branch` accepts any options valid for `git push`.
@@ -64,24 +66,24 @@ These options can be overriden (and thus restored to their defaults) by passing
64
66
 
65
67
  ### git sync
66
68
 
67
- `git sync [branch]` syncs the given local branch with the remote branch (defaults to master). On a branch called `add-markdown-support`, `git sync` is equivalent to the following:
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:
68
70
 
69
71
  $ git checkout master
70
72
  $ git pull
71
73
  $ git checkout add-markdown-support
72
74
 
73
- The main purpose of `git sync` is to prepare the current branch for merging with `master`:
75
+ The main purpose of `git sync` is to prepare the current branch for merging with the default branch:
74
76
 
75
77
  $ git sync
76
- $ git merge master
78
+ $ git merge master # or `main`, etc.
77
79
 
78
80
  (This is essentially equivalent to
79
81
 
80
82
  $ git fetch
81
83
  $ git merge origin/master
82
84
 
83
- but I don't like having `master` and `origin/master` be different since that means you have to remember to run `git pull` on `master` some time down the line.)
85
+ but I dont like having `master` and `origin/master` be different since that means you have to remember to run `git pull` on `master` some time down the line.)
84
86
 
85
87
  ## Installation
86
88
 
87
- gem install git-utils
89
+ gem install git-utils
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`, and the current
6
- # branch, which are preserved. We also support custom configuration via the
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/bin/git-graph ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Displays full repository history in graphical format
4
+ system 'git log --graph --oneline --decorate --all --full-history --author-date-order --no-notes'
@@ -3,9 +3,9 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
3
  require 'git-utils/merge_branch'
4
4
 
5
5
  # Merges the current branch into the given branch (defaults to master).
6
- # E.g., 'git merge-branch foobar' merges the current branch into foobar.
7
- # 'git merge-branch', merges the current branch into master.
8
- # git merge-branch uses the --no-ff --log options to ensure that the
6
+ # E.g., 'git merge-into-branch foobar' merges the current branch into foobar.
7
+ # 'git merge-into-branch', merges the current branch into master.
8
+ # git merge-into-branch uses the --no-ff --log options to ensure that the
9
9
  # merge creates a new commit object and that the individual commits appear
10
10
  # in the log file.
11
11
  exit Command.run!(MergeBranch, ARGV.dup)
data/bin/git-minor ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Makes minor changes.
4
+ system 'git commit -am "Make minor changes"'
data/bin/git-sync-fork ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'git-utils/sync_fork'
4
+
5
+ # Syncs the local master branch with remote.
6
+ exit Command.run!(SyncFork, ARGV.dup)
data/lib/git-utils.rb CHANGED
@@ -7,4 +7,5 @@ require "git-utils/delete_remote_branch"
7
7
  require "git-utils/push_branch"
8
8
  require "git-utils/switch"
9
9
  require "git-utils/sync"
10
+ require "git-utils/sync_fork"
10
11
  require "git-utils/pull_request"
@@ -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
@@ -4,7 +4,7 @@ class MergeBranch < Command
4
4
 
5
5
  def parser
6
6
  OptionParser.new do |opts|
7
- opts.banner = "Usage: git merge-branch [branch] [options]"
7
+ opts.banner = "Usage: git merge-into-branch [branch] [options]"
8
8
  opts.on_tail("-h", "--help", "this usage guide") do
9
9
  puts opts.to_s; exit 0
10
10
  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 master.
31
+ # that's the merge branch. Otherwise, it's the default branch.
32
32
  def target_branch
33
- self.known_options.first || 'master'
33
+ self.known_options.first || default_branch
34
34
  end
35
- end
35
+ end
@@ -34,7 +34,7 @@ class Open < Command
34
34
  origin_url.sub(pattern, replacement)
35
35
  end
36
36
 
37
- # Returns a command appropriate for executing at the command line..
37
+ # Returns a command appropriate for executing at the command line.
38
38
  def cmd
39
39
  if options[:print]
40
40
  puts page_url
@@ -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 || 'master'
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
@@ -0,0 +1,21 @@
1
+ require 'git-utils/command'
2
+
3
+ class SyncFork < Command
4
+
5
+ def parser
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Usage: git sync-fork [default]"
8
+ opts.on_tail("-h", "--help", "this usage guide") do
9
+ puts opts.to_s; exit 0
10
+ end
11
+ end
12
+ end
13
+
14
+ # Returns a command appropriate for executing at the command line.
15
+ def cmd
16
+ c = ["git checkout #{default_branch}"]
17
+ c << "git fetch upstream"
18
+ c << "git merge upstream/#{default_branch}"
19
+ c.join("\n")
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Utils
3
- VERSION = "0.7.0"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
  end
@@ -3,12 +3,12 @@ require 'spec_helper'
3
3
  describe MergeBranch do
4
4
 
5
5
  let(:command) { MergeBranch.new }
6
- before { command.stub(:current_branch).and_return('tau-manifesto') }
6
+ before { command.stub(:current_branch).and_return('tau-manifesto') }
7
7
  subject { command }
8
8
 
9
9
  its(:cmd) { should match /git merge/ }
10
10
 
11
- shared_examples "merge-branch with known options" do
11
+ shared_examples "merge-into-branch with known options" do
12
12
  subject { command }
13
13
  it "should not raise an error" do
14
14
  expect { command.parse }.not_to raise_error(OptionParser::InvalidOption)
@@ -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/ }
@@ -26,13 +41,13 @@ describe MergeBranch do
26
41
 
27
42
  describe "with some unknown options" do
28
43
  let(:command) { MergeBranch.new(['dev', '-o', '-a', '-z', '--foo']) }
29
- it_should_behave_like "merge-branch with known options"
44
+ it_should_behave_like "merge-into-branch with known options"
30
45
  its(:cmd) { should match /-a -z --foo/ }
31
46
  end
32
47
 
33
48
  describe "command-line command" do
34
- subject { `bin/git-merge-branch --debug development` }
49
+ subject { `bin/git-merge-into-branch --debug development` }
35
50
  it { should match /git checkout development/ }
36
51
  it { should match /git merge --no-ff --log/ }
37
52
  end
38
- end
53
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe SyncFork do
4
+
5
+ let(:command) { SyncFork.new }
6
+ subject { command }
7
+
8
+ its(:cmd) { should match /git checkout master/ }
9
+ its(:cmd) { should match /git fetch upstream/ }
10
+ its(:cmd) { should match /git merge upstream\/master/ }
11
+
12
+
13
+ describe "command-line command" do
14
+ subject { `bin/git-sync-fork --debug` }
15
+ it { should match /git fetch upstream/ }
16
+ end
17
+ end
metadata CHANGED
@@ -1,31 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
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: 2016-03-17 00:00:00.000000000 Z
11
+ date: 2021-04-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Add some Git utilities
14
14
  email:
15
15
  - michael@michaelhartl.com
16
16
  executables:
17
17
  - git-amend
18
- - git-anal
19
18
  - git-bump
20
19
  - git-cleanup
21
20
  - git-delete-remote-branch
22
- - git-merge-branch
21
+ - git-graph
22
+ - git-merge-into-branch
23
+ - git-minor
23
24
  - git-open
24
25
  - git-polish
25
26
  - git-pull-request
26
27
  - git-push-branch
27
28
  - git-switch
28
29
  - git-sync
30
+ - git-sync-fork
29
31
  - git-typo
30
32
  - git-undo
31
33
  extensions: []
@@ -40,17 +42,19 @@ files:
40
42
  - README.md
41
43
  - Rakefile
42
44
  - bin/git-amend
43
- - bin/git-anal
44
45
  - bin/git-bump
45
46
  - bin/git-cleanup
46
47
  - bin/git-delete-remote-branch
47
- - bin/git-merge-branch
48
+ - bin/git-graph
49
+ - bin/git-merge-into-branch
50
+ - bin/git-minor
48
51
  - bin/git-open
49
52
  - bin/git-polish
50
53
  - bin/git-pull-request
51
54
  - bin/git-push-branch
52
55
  - bin/git-switch
53
56
  - bin/git-sync
57
+ - bin/git-sync-fork
54
58
  - bin/git-typo
55
59
  - bin/git-undo
56
60
  - git-utils.gemspec
@@ -64,6 +68,7 @@ files:
64
68
  - lib/git-utils/push_branch.rb
65
69
  - lib/git-utils/switch.rb
66
70
  - lib/git-utils/sync.rb
71
+ - lib/git-utils/sync_fork.rb
67
72
  - lib/git-utils/version.rb
68
73
  - spec/.DS_Store
69
74
  - spec/commands/.DS_Store
@@ -74,6 +79,7 @@ files:
74
79
  - spec/commands/pull_request_spec.rb
75
80
  - spec/commands/push_branch_spec.rb
76
81
  - spec/commands/switch_spec.rb
82
+ - spec/commands/sync_fork_spec.rb
77
83
  - spec/commands/sync_spec.rb
78
84
  - spec/spec_helper.rb
79
85
  homepage: https://github.com/mhartl/git-utils
@@ -95,8 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
101
  - !ruby/object:Gem::Version
96
102
  version: '0'
97
103
  requirements: []
98
- rubyforge_project:
99
- rubygems_version: 2.4.5.1
104
+ rubygems_version: 3.1.4
100
105
  signing_key:
101
106
  specification_version: 4
102
107
  summary: See the README for full documentation
@@ -110,5 +115,6 @@ test_files:
110
115
  - spec/commands/pull_request_spec.rb
111
116
  - spec/commands/push_branch_spec.rb
112
117
  - spec/commands/switch_spec.rb
118
+ - spec/commands/sync_fork_spec.rb
113
119
  - spec/commands/sync_spec.rb
114
120
  - spec/spec_helper.rb
data/bin/git-anal DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Makes anal changes.
4
- system 'git commit -am "Make anal changes"'