Skip to content

adding boolean functions for git status #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding file to untracked?; adding tests for the reminder of the new f…
…unctions
  • Loading branch information
tarcinil committed Feb 24, 2018
commit 082c4a7c298d7aee7623f0d427558f524b73d3ee
2 changes: 1 addition & 1 deletion lib/git/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def untracked
@files.select { |_k, f| f.untracked }
end

def untracked?
def untracked?(file)
untracked.member?(file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the new methods added, would you mind adding YARD-style comments that describes briefly:

  • What they do
  • What the expected types of the input and return values are

The new methods added in this PR are:

  • changed?
  • added?
  • deleted?
  • untracked?

Something like this will do:

#
# Determines whether the given file has been added to the repository
#
# @param file [String] The name of the file.
# @return [Boolean]

This way, it is clearer for readers of the code what the intent of these (public API methods) is.

end

Expand Down
38 changes: 38 additions & 0 deletions tests/units/test_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,42 @@ def test_added_boolean
assert(git.status.added?('test_file_1'))
end
end

def test_changed_boolean
in_temp_dir do |path|
git = Git.clone(@wdir, 'test_dot_files_status')

create_file('test_dot_files_status/test_file_1', 'content tets_file_1')

git.add('test_file_1')
git.commit('message')
update_file('test_dot_files_status/test_file_1', 'update_content tets_file_1')

assert(git.status.changed?('test_file_1'))
end
end

def test_deleted_boolean
in_temp_dir do |path|
git = Git.clone(@wdir, 'test_dot_files_status')

create_file('test_dot_files_status/test_file_1', 'content tets_file_1')

git.add('test_file_1')
git.commit('message')
delete_file('test_dot_files_status/test_file_1')

assert(git.status.deleted?('test_file_1'))
end
end

def test_untracked_boolean
in_temp_dir do |path|
git = Git.clone(@wdir, 'test_dot_files_status')

create_file('test_dot_files_status/test_file_1', 'content tets_file_1')

assert(git.status.untracked?('test_file_1'))
end
end
end