Skip to content
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

Add functions to work with git #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions src/git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env

set -o errexit
set -o pipefail


function files_changed() {
FROM_COMMIT=$1
TO_COMMIT=$2

git diff --name-only $FROM_COMMIT..$TO_COMMIT
}
25 changes: 25 additions & 0 deletions tests/git.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bats

setup() {
source src/git.sh
}

@test "git>file_changes recognizes added files as changed files" {
FROM_COMMIT=7c5b539
TO_COMMIT=b108196

run files_changed $FROM_COMMIT $TO_COMMIT

[ $status -eq 0 ]
[ "${lines[1]}" = "tests/it-works.bats" ]
}


@test "git>file_changes recognizes modified files as changed files" {
FROM_COMMIT=7c5b539
TO_COMMIT=b108196

run files_changed $FROM_COMMIT $TO_COMMIT
[ $status -eq 0 ]
[ "${lines[0]}" = "README.md" ]
}