From 37860d174e39bee68d0d23bbc294ebb0aec32ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Freiheit?= Date: Thu, 16 Jan 2020 15:16:12 +0200 Subject: [PATCH] Add simple function to detect file changes between two commits --- src/git.sh | 12 ++++++++++++ tests/git.bats | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/git.sh create mode 100644 tests/git.bats diff --git a/src/git.sh b/src/git.sh new file mode 100644 index 0000000..53ede32 --- /dev/null +++ b/src/git.sh @@ -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 +} diff --git a/tests/git.bats b/tests/git.bats new file mode 100644 index 0000000..77de1d0 --- /dev/null +++ b/tests/git.bats @@ -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" ] +}