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 +4 -4
- data/bin/furi-git-prompt +1 -0
- data/lib/furi/git/git.rb +21 -1
- data/lib/furi/git/git_prompt.rb +8 -4
- data/lib/furi/git/git_system_call.rb +11 -2
- data/lib/furi/git/prompt/version.rb +1 -1
- data/spec/furi/git/git_spec.rb +26 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76d44a73da7ac930bac19fd31de5a7d464828f7d
|
|
4
|
+
data.tar.gz: 9f5493454368bdcd4c2825383c1931548f260056
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 532d7412a5956dc3d7530eb9f62c25fe6812701d26a0eccda25ee8b87a2008820531a0c14a43383bb77e68234688240c670d88ca5d9a238c91ea44ea15ab9540
|
|
7
|
+
data.tar.gz: 1a18661f268de41d4f2b7a5c0d71b925007dc6a064bedda02e1ac84cab86d82c1e783c4f24f3f008da184e6632e1f0d32ea543749c922fcb999d21ff14defbc8
|
data/bin/furi-git-prompt
CHANGED
data/lib/furi/git/git.rb
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
-
|
|
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
|
data/lib/furi/git/git_prompt.rb
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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.
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18
|
+
''
|
|
10
19
|
end
|
|
11
20
|
end
|
|
12
21
|
end
|
data/spec/furi/git/git_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'rspec'
|
|
2
2
|
|
|
3
|
-
|
|
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(
|
|
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
|