furi-git-prompt 0.0.8 → 0.0.9

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
2
  SHA1:
3
- metadata.gz: 3e534f08d4c5688da28662520526ce4424b6a4c1
4
- data.tar.gz: c96d8b5fe716578224def400241707351c911dff
3
+ metadata.gz: 76d44a73da7ac930bac19fd31de5a7d464828f7d
4
+ data.tar.gz: 9f5493454368bdcd4c2825383c1931548f260056
5
5
  SHA512:
6
- metadata.gz: b954a8a466cd7c339cf6cc1d7069f3c3c4a710a9b1b4c1b96c36b2b112cfe60a94bd208c6056efe221a5600b66a16728ec90f1d75009b682cb8f4d912242a950
7
- data.tar.gz: 6f4a7996baf3fbff67b4c25511b95b3502bf2470f89e0b120467aac6d7e995989ad3020bb40cb143bbcc4463bb14c45e70d0e33b452f91713c84ec6334b40a52
6
+ metadata.gz: 532d7412a5956dc3d7530eb9f62c25fe6812701d26a0eccda25ee8b87a2008820531a0c14a43383bb77e68234688240c670d88ca5d9a238c91ea44ea15ab9540
7
+ data.tar.gz: 1a18661f268de41d4f2b7a5c0d71b925007dc6a064bedda02e1ac84cab86d82c1e783c4f24f3f008da184e6632e1f0d32ea543749c922fcb999d21ff14defbc8
data/bin/furi-git-prompt CHANGED
@@ -5,3 +5,4 @@ require 'furi/git/git_prompt'
5
5
 
6
6
  puts GitPrompt.version
7
7
  puts GitPrompt.branch
8
+ puts GitPrompt.added_files
data/lib/furi/git/git.rb CHANGED
@@ -1,10 +1,30 @@
1
- require 'furi/git/git_system_call'
1
+ require_relative 'git_system_call'
2
2
 
3
3
  class Git
4
4
  def initialize
5
5
  @git_system = GitSystemCall.new
6
6
  end
7
7
 
8
+ def added_files
9
+ status = @git_system.git_status
10
+ block_type = :none
11
+ added_files_counter = 0
12
+ if status.empty?
13
+ ''
14
+ else
15
+ status.each_line do |line|
16
+ if block_type == :none
17
+ if line.include? '# Untracked files:'
18
+ block_type = :untracked_files
19
+ end
20
+ elsif block_type == :untracked_files
21
+ added_files_counter += 1 if line.match(/#\s[\d\w]+/i)
22
+ end
23
+ end
24
+ '+' + added_files_counter.to_s
25
+ end
26
+ end
27
+
8
28
  def branch
9
29
  git_branch_match = @git_system.git_branch.match(/\* ([^\s.]*)/i)
10
30
  if git_branch_match
@@ -1,12 +1,16 @@
1
- require 'furi/git/prompt/version'
2
- require 'furi/git/git'
1
+ require_relative 'prompt/version'
2
+ require_relative 'git'
3
3
 
4
4
  module GitPrompt
5
+ def self.version
6
+ Furi::Git::Prompt::VERSION
7
+ end
8
+
5
9
  def self.branch
6
10
  Git.new.branch
7
11
  end
8
12
 
9
- def self.version
10
- Furi::Git::Prompt::VERSION
13
+ def self.added_files
14
+ Git.new.added_files
11
15
  end
12
16
  end
@@ -2,11 +2,20 @@ require 'open3'
2
2
 
3
3
  class GitSystemCall
4
4
  def git_branch
5
- stdout_str, stdout_err, status = Open3.capture3('git branch')
5
+ call 'git branch'
6
+ end
7
+
8
+ def git_status
9
+ call 'git status'
10
+ end
11
+
12
+ private
13
+ def call(command)
14
+ stdout_str, stdout_err, status = Open3.capture3(command)
6
15
  if status.exitstatus == 0
7
16
  stdout_str
8
17
  else
9
- stdout_err
18
+ ''
10
19
  end
11
20
  end
12
21
  end
@@ -1,7 +1,7 @@
1
1
  module Furi
2
2
  module Git
3
3
  module Prompt
4
- VERSION = '0.0.8'
4
+ VERSION = '0.0.9'
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  require 'rspec'
2
2
 
3
- require 'furi/git/git'
3
+ require_relative '../../../lib/furi/git/git'
4
4
 
5
5
  describe Git do
6
6
  it 'shows the current branch name of a git repository' do
@@ -27,9 +27,33 @@ describe Git do
27
27
 
28
28
  context 'no git repository exist' do
29
29
  it 'shows nothing' do
30
- GitSystemCall.any_instance.stub(:git_branch).and_return("fatal: Not a git repository (or any of the parent directories): .git\n")
30
+ GitSystemCall.any_instance.stub(:git_branch).and_return('')
31
31
  Git.new.branch.should be_empty
32
32
  end
33
33
  end
34
34
 
35
+ context 'one files was added, modfied and deleted' do
36
+ before do
37
+ @git_status =
38
+ '# On branch c-branch
39
+ # Changes not staged for commit:
40
+ # (use "git add/rm <file>..." to update what will be committed)
41
+ # (use "git checkout -- <file>..." to discard changes in working directory)
42
+ #
43
+ # modified: mod_file
44
+ # deleted: del_file
45
+ #
46
+ # Untracked files:
47
+ # (use "git add <file>..." to include in what will be committed)
48
+ #
49
+ # new_file
50
+ no changes added to commit (use "git add" and/or "git commit -a")'
51
+
52
+ end
53
+
54
+ it 'shows one file was added' do
55
+ GitSystemCall.any_instance.stub(:git_status).and_return(@git_status)
56
+ Git.new.added_files.should == '+1'
57
+ end
58
+ end
35
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: furi-git-prompt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Pack