Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix tab completion for branches containing dots #117

Merged
merged 1 commit into from

3 participants

@georgebrock
Owner

Completion after the dot would be seen as the beginning of a new argument. This is correct behaviour for two dots (e.g. HEAD~2..master) but not for one dot (e.g. fix-v1.4)

This should fix #87

@georgebrock georgebrock added this to the 0.5 milestone
@georgebrock georgebrock added the bug label
@croaky
Owner

There was more change to the spec file than I expected for a two character implementation change. The information like repo_head ended up being pretty far away in the file from the specs that test the dot-ness, so it is starting to feel a little Mystery Guest-y.

Other than maybe re-working that a little bit so there's separate describe blocks or a way to inject the v1.0 etc. bits from the dot spec, this looks good to me.

@georgebrock
Owner

Thanks for the feedback, @croaky. I've refactored the spec and replaced the let blocks with a single factory method. The individual examples can pass in the setup they need to the factory method, which keeps the setup and the expectations nice and close and also is more in keeping with the style of other specs.

@croaky
Owner

Very nice. I have a much better understanding of gitsh's completion functionality after reading the current spec.

Looks great! Ready to squash and merge at your discretion.

George Brocklehurst and Alex Topalov Fix tab completion for branches with a dot
Completion after the dot would be seen as a new branch name. This is correct
behaviour for two dots (e.g. HEAD~2..master) but not for one dot (e.g.
fix-v1.4)

Includes a refactoring of the Completer unit spec, to reduce the amount of
repetition.
d6b9a16
@georgebrock georgebrock merged commit d6b9a16 into master
@georgebrock georgebrock deleted the gb-fix-dot-completion branch
@georgebrock
Owner

Thanks, Dan. Squashed and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2014
  1. @georgebrock

    Fix tab completion for branches with a dot

    George Brocklehurst and Alex Topalov authored georgebrock committed
    Completion after the dot would be seen as a new branch name. This is correct
    behaviour for two dots (e.g. HEAD~2..master) but not for one dot (e.g.
    fix-v1.4)
    
    Includes a refactoring of the Completer unit spec, to reduce the amount of
    repetition.
This page is out of date. Refresh to see the latest.
Showing with 79 additions and 60 deletions.
  1. +1 −1  lib/gitsh/completer.rb
  2. +78 −59 spec/units/completer_spec.rb
View
2  lib/gitsh/completer.rb
@@ -75,7 +75,7 @@ def suffix(_)
end
class HeadCompleter < TextCompleter
- SEPARATORS = /(?:\.+|[:^~\\])/
+ SEPARATORS = /(?:\.\.+|[:^~\\])/
def initialize(input, env)
super(input)
View
137 spec/units/completer_spec.rb
@@ -2,77 +2,96 @@
require 'gitsh/completer'
describe Gitsh::Completer do
- it 'completes commands and aliases' do
- readline = stub('Readline', line_buffer: '')
- env = stub(
- 'Environment',
- git_commands: %w( stage stash status add commit ),
- git_aliases: %w( adder )
- )
- internal_command = stub('InternalCommand', commands: %w( :set :exit ))
- completer = Gitsh::Completer.new(readline, env, internal_command)
-
- expect(completer.call('sta')).to eq ['stage ', 'stash ', 'status ']
- expect(completer.call('ad')).to eq ['add ', 'adder ']
- end
+ describe '#call' do
+ context 'when completing commands' do
+ it 'completes commands and aliases' do
+ completer = build_completer(
+ input: '',
+ git_commands: %w( stage stash status add commit ),
+ git_aliases: %w( adder )
+ )
- it 'completes internal commands' do
- readline = stub('Readline', line_buffer: '')
- env = stub('Environment', git_commands: %w( stage stash ), git_aliases: [])
- internal_command = stub('InternalCommand', commands: %w( :set :exit ))
- completer = Gitsh::Completer.new(readline, env, internal_command)
+ expect(completer.call('sta')).to eq ['stage ', 'stash ', 'status ']
+ expect(completer.call('ad')).to eq ['add ', 'adder ']
+ end
- expect(completer.call(':')).to eq [':set ', ':exit ']
- expect(completer.call(':s')).to eq [':set ']
- end
+ it 'completes internal commands' do
+ completer = build_completer(
+ input: '',
+ internal_commands: %w( :set :exit )
+ )
- it 'completes heads when a command has been entered' do
- readline = stub('Readline', line_buffer: 'checkout ')
- env = stub('Environment', repo_heads: %w( master my-feature v1.0 ))
- internal_command = stub('InternalCommand')
- completer = Gitsh::Completer.new(readline, env, internal_command)
+ expect(completer.call(':')).to eq [':set ', ':exit ']
+ expect(completer.call(':s')).to eq [':set ']
+ end
+ end
- expect(completer.call('')).to include 'master ', 'my-feature ', 'v1.0 '
- expect(completer.call('m')).to include 'master ', 'my-feature '
- expect(completer.call('m')).not_to include 'v1.0 '
- end
+ context 'when completing arguments' do
+ it 'completes heads when a command has been entered' do
+ completer = build_completer(
+ input: 'checkout ',
+ repo_heads: %w( master my-feature v1.0 )
+ )
- it 'completes paths beginning with a ~ character' do
- readline = stub('Readline', line_buffer: ':cd ')
- env = stub('Environment', repo_heads: %w( master ))
- internal_command = stub('InternalCommand')
- completer = Gitsh::Completer.new(readline, env, internal_command)
+ expect(completer.call('')).to include 'master ', 'my-feature ', 'v1.0 '
+ expect(completer.call('m')).to include 'master ', 'my-feature '
+ expect(completer.call('m')).not_to include 'v1.0 '
+ end
- expect(completer.call('~/')).to include "#{first_regular_file('~')} "
- end
+ it 'completes head when branch include a dot' do
+ completer = build_completer(
+ input: 'checkout ',
+ repo_heads: %w( fix-v1.5 fix-v1.6 )
+ )
- it 'completes paths containing .. and .' do
- project_root = File.expand_path('../../../', __FILE__)
- path = File.join(project_root, 'spec/./units/../units')
- readline = stub('Readline', line_buffer: ':cd ')
- env = stub('Environment', repo_heads: %w( master ))
- internal_command = stub('InternalCommand')
- completer = Gitsh::Completer.new(readline, env, internal_command)
+ expect(completer.call('fix-v1.')).to include 'fix-v1.5 ', 'fix-v1.6 '
+ end
- expect(completer.call("#{path}/")).to include "#{first_regular_file(path)} "
- end
+ it 'completes heads starting with :' do
+ completer = build_completer(
+ input: 'checkout ',
+ repo_heads: %w( master my-feature )
+ )
- it 'completes heads starting with :' do
- readline = stub('Readline', line_buffer: 'push ')
- env = stub('Environment', repo_heads: %w( master hello-branch ))
- internal_command = stub('InternalCommand')
- completer = Gitsh::Completer.new(readline, env, internal_command)
+ expect(completer.call('master:m')).to include 'master:my-feature '
+ end
- expect(completer.call('master:h')).to include 'master:hello-branch '
- end
+ it 'ignores input before punctuation when completing heads' do
+ completer = build_completer(
+ input: 'checkout ',
+ repo_heads: %w( master my-feature )
+ )
- it 'ignores input before punctuation when completing heads' do
- readline = stub('Readline', line_buffer: 'push ')
- env = stub('Environment', repo_heads: %w( master ))
- internal_command = stub('InternalCommand')
- completer = Gitsh::Completer.new(readline, env, internal_command)
+ expect(completer.call('mas:')).to include 'mas:master ', 'mas:my-feature '
+ end
+
+ it 'completes paths beginning with a ~ character' do
+ completer = build_completer(input: 'add ')
+
+ expect(completer.call('~/')).to include "#{first_regular_file('~')} "
+ end
+
+ it 'completes paths containing .. and .' do
+ completer = build_completer(input: 'add ')
+ project_root = File.expand_path('../../../', __FILE__)
+ path = File.join(project_root, 'spec/./units/../units')
+
+ expect(completer.call("#{path}/")).to include "#{first_regular_file(path)} "
+ end
+ end
+ end
- expect(completer.call('mas:')).to eq [ 'mas:master ' ]
+ def build_completer(options)
+ readline = stub('Readline', line_buffer: options.fetch(:input))
+ env = stub('Environment', {
+ git_commands: options.fetch(:git_commands, %w( add commit )),
+ git_aliases: options.fetch(:git_aliases, %w( graph )),
+ repo_heads: options.fetch(:repo_heads, %w( master ))
+ })
+ internal_command = stub('InternalCommand', {
+ commands: options.fetch(:internal_commands, %w( :set :exit ))
+ })
+ Gitsh::Completer.new(readline, env, internal_command)
end
def first_regular_file(directory)
Something went wrong with that request. Please try again.