2016-03-24 00:18:33 +00:00
|
|
|
load common
|
|
|
|
load_fixtures
|
2016-04-06 17:33:42 +00:00
|
|
|
status=;output=; #; populated by bats run()
|
2016-03-24 00:18:33 +00:00
|
|
|
|
|
|
|
setup() {
|
|
|
|
destroy_tmp
|
|
|
|
create_worktree "$T_DIR_WORK"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'init'" {
|
|
|
|
echo "
|
|
|
|
When 'init' command is provided,
|
|
|
|
Create new repo with attributes:
|
|
|
|
- 0600 permissions
|
|
|
|
- not bare
|
|
|
|
- worktree = \$HOME
|
|
|
|
- showUntrackedFiles = no
|
|
|
|
- yadm.managed = true
|
|
|
|
Report the repo as initialized
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
#; run init
|
2016-04-06 17:33:42 +00:00
|
|
|
run "${T_YADM_Y[@]}" init
|
2016-03-24 00:18:33 +00:00
|
|
|
|
|
|
|
#; validate status and output
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[[ "$output" =~ Initialized ]]
|
|
|
|
|
|
|
|
#; validate repo attributes
|
2016-04-06 17:33:42 +00:00
|
|
|
test_perms "$T_DIR_REPO" "drw.--.--."
|
|
|
|
test_repo_attribute "$T_DIR_REPO" core.bare false
|
|
|
|
test_repo_attribute "$T_DIR_REPO" core.worktree "$HOME"
|
|
|
|
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no
|
|
|
|
test_repo_attribute "$T_DIR_REPO" yadm.managed true
|
2016-03-24 00:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'init' -w (alternate worktree)" {
|
|
|
|
echo "
|
|
|
|
When 'init' command is provided,
|
|
|
|
and '-w' is provided,
|
|
|
|
Create new repo with attributes:
|
|
|
|
- 0600 permissions
|
|
|
|
- not bare
|
|
|
|
- worktree = \$YADM_WORK
|
|
|
|
- showUntrackedFiles = no
|
|
|
|
- yadm.managed = true
|
|
|
|
Report the repo as initialized
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
#; run init
|
2016-04-06 17:33:42 +00:00
|
|
|
run "${T_YADM_Y[@]}" init -w "$T_DIR_WORK"
|
2016-03-24 00:18:33 +00:00
|
|
|
|
|
|
|
#; validate status and output
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[[ "$output" =~ Initialized ]]
|
|
|
|
|
|
|
|
#; validate repo attributes
|
2016-04-06 17:33:42 +00:00
|
|
|
test_perms "$T_DIR_REPO" "drw.--.--."
|
|
|
|
test_repo_attribute "$T_DIR_REPO" core.bare false
|
|
|
|
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK"
|
|
|
|
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no
|
|
|
|
test_repo_attribute "$T_DIR_REPO" yadm.managed true
|
2016-03-24 00:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'init' (existing repo)" {
|
|
|
|
echo "
|
|
|
|
When 'init' command is provided,
|
|
|
|
and a repo already exists,
|
|
|
|
Refuse to create a new repo
|
|
|
|
Exit with 1
|
|
|
|
"
|
|
|
|
|
|
|
|
#; create existing repo content
|
2016-04-06 17:33:42 +00:00
|
|
|
mkdir -p "$T_DIR_REPO"
|
2016-03-24 00:18:33 +00:00
|
|
|
local testfile="$T_DIR_REPO/testfile"
|
|
|
|
touch "$testfile"
|
|
|
|
|
|
|
|
#; run init
|
2016-04-06 17:33:42 +00:00
|
|
|
run "${T_YADM_Y[@]}" init
|
2016-03-24 00:18:33 +00:00
|
|
|
|
|
|
|
#; validate status and output
|
|
|
|
[ $status -eq 1 ]
|
|
|
|
[[ "$output" =~ already.exists ]]
|
|
|
|
|
|
|
|
#; verify existing repo is intact
|
2016-04-06 17:33:42 +00:00
|
|
|
if [ ! -e "$testfile" ]; then
|
2016-03-24 00:18:33 +00:00
|
|
|
echo "ERROR: existing repo has been changed"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'init' -f (force overwrite repo)" {
|
|
|
|
echo "
|
|
|
|
When 'init' command is provided,
|
|
|
|
and '-f' is provided
|
|
|
|
and a repo already exists,
|
|
|
|
Remove existing repo
|
|
|
|
Create new repo with attributes:
|
|
|
|
- 0600 permissions
|
|
|
|
- not bare
|
|
|
|
- worktree = \$HOME
|
|
|
|
- showUntrackedFiles = no
|
|
|
|
- yadm.managed = true
|
|
|
|
Report the repo as initialized
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
#; create existing repo content
|
2016-04-06 17:33:42 +00:00
|
|
|
mkdir -p "$T_DIR_REPO"
|
2016-03-24 00:18:33 +00:00
|
|
|
local testfile="$T_DIR_REPO/testfile"
|
|
|
|
touch "$testfile"
|
|
|
|
|
|
|
|
#; run init
|
2016-04-06 17:33:42 +00:00
|
|
|
run "${T_YADM_Y[@]}" init -f
|
2016-03-24 00:18:33 +00:00
|
|
|
|
|
|
|
#; validate status and output
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[[ "$output" =~ Initialized ]]
|
|
|
|
|
|
|
|
#; verify existing repo is gone
|
2016-04-06 17:33:42 +00:00
|
|
|
if [ -e "$testfile" ]; then
|
2016-03-24 00:18:33 +00:00
|
|
|
echo "ERROR: existing repo files remain"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#; validate repo attributes
|
2016-04-06 17:33:42 +00:00
|
|
|
test_perms "$T_DIR_REPO" "drw.--.--."
|
|
|
|
test_repo_attribute "$T_DIR_REPO" core.bare false
|
|
|
|
test_repo_attribute "$T_DIR_REPO" core.worktree "$HOME"
|
|
|
|
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no
|
|
|
|
test_repo_attribute "$T_DIR_REPO" yadm.managed true
|
2016-03-24 00:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'init' -f -w (force overwrite repo with alternate worktree)" {
|
|
|
|
echo "
|
|
|
|
When 'init' command is provided,
|
|
|
|
and '-f' is provided
|
|
|
|
and '-w' is provided
|
|
|
|
and a repo already exists,
|
|
|
|
Remove existing repo
|
|
|
|
Create new repo with attributes:
|
|
|
|
- 0600 permissions
|
|
|
|
- not bare
|
|
|
|
- worktree = \$YADM_WORK
|
|
|
|
- showUntrackedFiles = no
|
|
|
|
- yadm.managed = true
|
|
|
|
Report the repo as initialized
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
#; create existing repo content
|
2016-04-06 17:33:42 +00:00
|
|
|
mkdir -p "$T_DIR_REPO"
|
2016-03-24 00:18:33 +00:00
|
|
|
local testfile="$T_DIR_REPO/testfile"
|
|
|
|
touch "$testfile"
|
|
|
|
|
|
|
|
#; run init
|
2016-04-06 17:33:42 +00:00
|
|
|
run "${T_YADM_Y[@]}" init -f -w "$T_DIR_WORK"
|
2016-03-24 00:18:33 +00:00
|
|
|
|
|
|
|
#; validate status and output
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[[ "$output" =~ Initialized ]]
|
|
|
|
|
|
|
|
#; verify existing repo is gone
|
2016-04-06 17:33:42 +00:00
|
|
|
if [ -e "$testfile" ]; then
|
2016-03-24 00:18:33 +00:00
|
|
|
echo "ERROR: existing repo files remain"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#; validate repo attributes
|
2016-04-06 17:33:42 +00:00
|
|
|
test_perms "$T_DIR_REPO" "drw.--.--."
|
|
|
|
test_repo_attribute "$T_DIR_REPO" core.bare false
|
|
|
|
test_repo_attribute "$T_DIR_REPO" core.worktree "$T_DIR_WORK"
|
|
|
|
test_repo_attribute "$T_DIR_REPO" status.showUntrackedFiles no
|
|
|
|
test_repo_attribute "$T_DIR_REPO" yadm.managed true
|
2016-03-24 00:18:33 +00:00
|
|
|
}
|