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 an acc test covering failures when reading .git #2223

Merged
merged 5 commits into from
Jan 24, 2025
Merged
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
2 changes: 2 additions & 0 deletions acceptance/bundle/git-permerror/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bundle:
name: git-permerror
78 changes: 78 additions & 0 deletions acceptance/bundle/git-permerror/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
=== No permission to access .git. Badness: inferred flag is set to true even though we did not infer branch. bundle_root_path is not correct in subdir case.

>>> chmod 000 .git

>>> $CLI bundle validate
Error: unable to load repository specific gitconfig: open config: permission denied

Name: git-permerror
Target: default
Workspace:
User: $USERNAME
Path: /Workspace/Users/$USERNAME/.bundle/git-permerror/default

Found 1 error

Exit code: 1

>>> $CLI bundle validate -o json
Error: unable to load repository specific gitconfig: open config: permission denied


Exit code: 1
{
"bundle_root_path": ".",
"inferred": true
}

>>> withdir subdir/a/b $CLI bundle validate -o json
Error: unable to load repository specific gitconfig: open config: permission denied


Exit code: 1
{
"bundle_root_path": ".",
"inferred": true
}


=== No permissions to read .git/HEAD. Badness: warning is not shown. inferred is incorrectly set to true. bundle_root_path is not correct in subdir case.

>>> chmod 000 .git/HEAD

>>> $CLI bundle validate -o json
{
"bundle_root_path": ".",
"inferred": true
}

>>> withdir subdir/a/b $CLI bundle validate -o json
{
"bundle_root_path": ".",
"inferred": true
}


=== No permissions to read .git/config. Badness: inferred is incorretly set to true. bundle_root_path is not correct is subdir case.

>>> chmod 000 .git/config

>>> $CLI bundle validate -o json
Error: unable to load repository specific gitconfig: open config: permission denied


Exit code: 1
{
"bundle_root_path": ".",
"inferred": true
}

>>> withdir subdir/a/b $CLI bundle validate -o json
Error: unable to load repository specific gitconfig: open config: permission denied


Exit code: 1
{
"bundle_root_path": ".",
"inferred": true
}
25 changes: 25 additions & 0 deletions acceptance/bundle/git-permerror/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mkdir myrepo
cd myrepo
cp ../databricks.yml .
git-repo-init
mkdir -p subdir/a/b

printf "=== No permission to access .git. Badness: inferred flag is set to true even though we did not infer branch. bundle_root_path is not correct in subdir case.\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

This can use the "title" helper instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tbh, that helper feels unnecessary to me. It also does not add a new line at the end for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, in some cases I want a couple of front newlines and in one case I won't none.

trace chmod 000 .git
errcode trace $CLI bundle validate
errcode trace $CLI bundle validate -o json | jq .bundle.git
errcode trace withdir subdir/a/b $CLI bundle validate -o json | jq .bundle.git

printf "\n\n=== No permissions to read .git/HEAD. Badness: warning is not shown. inferred is incorrectly set to true. bundle_root_path is not correct in subdir case.\n"
chmod 700 .git
trace chmod 000 .git/HEAD
errcode trace $CLI bundle validate -o json | jq .bundle.git
errcode trace withdir subdir/a/b $CLI bundle validate -o json | jq .bundle.git

printf "\n\n=== No permissions to read .git/config. Badness: inferred is incorretly set to true. bundle_root_path is not correct is subdir case.\n"
chmod 666 .git/HEAD
trace chmod 000 .git/config
errcode trace $CLI bundle validate -o json | jq .bundle.git
errcode trace withdir subdir/a/b $CLI bundle validate -o json | jq .bundle.git

rm -fr .git
5 changes: 5 additions & 0 deletions acceptance/bundle/git-permerror/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Badness = "Warning logs not shown; inferred flag is set to true incorrect; bundle_root_path is not correct"

[GOOS]
# This test relies on chmod which does not work on Windows
windows = false
11 changes: 11 additions & 0 deletions acceptance/script.prepare
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ title() {
local label="$1"
printf "\n=== %s" "$label"
}

withdir() {
local dir="$1"
shift
local orig_dir="$(pwd)"
cd "$dir" || return $?
"$@"
local exit_code=$?
cd "$orig_dir" || return $?
return $exit_code
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's easier/shorter to just use a subshell.

E.g.

(
  cd subdir/a/b
  errcode trace $CLI bundle validate -o json | jq .bundle.git
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean using subshell directly in script?

It's not shorter, especially if you consider that you also want to trace cd command and then you have it appearing in the output as a separate line.

Copy link
Contributor Author

@denik denik Jan 24, 2025

Choose a reason for hiding this comment

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

So we're comparing:

script:
errcode trace withdir subdir/a/b $CLI bundle validate -o json | jq .bundle.git

output:
>>> withdir subdir/a/b $CLI bundle validate -o json

vs

script:

(
    trace cd subdir/a/b
    errcode trace $CLI bundle validate -o json | jq .bundle.git
)

output:

>>> cd subdir/a/b
>>> $CLI bundle validate -o json

Note, in the output you cannot see that you're inside a subshell and that cd subdir/a/b only applies to next statement.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, thanks.

Loading