Skip to content
Open
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
55 changes: 55 additions & 0 deletions test/00-git-config.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

set -e

source test/setup

use Test::More

note "Define project-wide GIT setup for all tests"

# Get git-subrepo project top directory
PROJ_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )

if [ -z "${PROJ_DIR}" ] || [ "${HOME}" != "${PROJ_DIR}" ]; then
is "${HOME}" "${PROJ_DIR}" \
"To define project-wide GIT setup for all tests: HOME '${HOME}' should equal PROJ_DIR '${PROJ_DIR}'"
else

# Real GIT configuration for tests is set here:
rm -f "${PROJ_DIR}/.gitconfig"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not ok with removing the .gitconfig from a person's working directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi again,
i thought i made sure, that HOME is temporarily set to $PWD in 'test/setup' for the duration of running tests and only when git-subrepo's clone directory (PROJ_DIR) and HOME match, then rewrite tests-defined git configuration in PROJ_DIR.
regards, Samo

git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git config --global init.defaultBranch "master"
git config --global --add safe.directory "${PROJ_DIR}"
git config --global --add safe.directory "${PROJ_DIR}/.git"
git config --list

test-exists "${PROJ_DIR}/.gitconfig"

# Running tests depends on the whole project being git initialized.
# So, git initialize the project, if necessary.
if [ ! -d "${PROJ_DIR}/.git" ]; then
cd "${PROJ_DIR}"
git init .
git add .
git commit -a -m"Initial commit"
cd -
fi

test-exists "${PROJ_DIR}/.git/"

# Running tests depends on the whole project not being in a GIT detached HEAD state.
if ! git symbolic-ref --short --quiet HEAD &> /dev/null; then
git checkout -b test
fi

ok "$(
git symbolic-ref --short --quiet HEAD &> /dev/null
)" "Whole project is not in a GIT detached HEAD state"

fi

done_testing

teardown
7 changes: 7 additions & 0 deletions test/setup
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ source "$PWD"/.rc
# Get the location of this script
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

# Disable any GIT configuration set outside this 'git-subrepo' project.
# Real GIT configuration for tests is set through the first test
# (00-git-config.t).
export XDG_CONFIG_HOME=$PWD
export HOME=$PWD
export GIT_CONFIG_NOSYSTEM=1

BASHLIB=$(
find "$PWD"/ -type d -name bin -o -type d -name lib | tr '\n' ':'
)
Expand Down