Skip to content

Commit

Permalink
Add --ignore-dirty-git option to test and install commands
Browse files Browse the repository at this point in the history
  • Loading branch information
timwoj committed Jun 20, 2023
1 parent e1d8271 commit ecf4c2e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions testing/baselines/tests.install-ignore-dirty/output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
15 changes: 15 additions & 0 deletions testing/tests/ignore-dirty
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Test commands with the --ignore-dirty-git argument
# @TEST-EXEC: bash %INPUT
# @TEST-EXEC: test -f dirty-test.bundle

CONFIG=$(pwd)/config

echo "# testing dirty git repos" >> ./packages/bar/zkg.meta

zkg --config=$CONFIG test --ignore-dirty-git ./packages/bar
zkg --config=$CONFIG install --force --ignore-dirty-git ./packages/bar

echo "[bundle]" > ./bundle-manifest
echo "./packages/bar=HEAD" >> ./bundle-manifest

zkg --config=$CONFIG bundle --force --ignore-dirty-git --manifest ./bundle-manifest -- dirty-test.bundle
8 changes: 7 additions & 1 deletion testing/tests/install-invalid
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ mkdir ./packages/notagitrepo
zkg --config=$CONFIG install --force ./packages/notagitrepo

mkdir ./packages/dirtyrepo
( cd ./packages/dirtyrepo && git init . && touch README && git add README && git commit -m "Initial commit")
( cd ./packages/dirtyrepo && \
git init . && \
touch README && \
cp ${PACKAGES}/foo/zkg.meta zkg.meta && \
git add README zkg.meta && \
git commit -m "Initial commit")
echo README > ./packages/dirtyrepo/README

zkg --config=$CONFIG install --force ./packages/dirtyrepo
31 changes: 26 additions & 5 deletions zkg
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,12 @@ def is_local_git_repo_dirty(git_url):
return repo.is_dirty(untracked_files=True)


def check_local_git_repo(git_url):
def check_local_git_repo(git_url, allow_dirty):
if is_local_git_repo_url(git_url):
if not is_local_git_repo(git_url):
print_error(f"error: path {git_url} is not a git repository")
return False
if is_local_git_repo_dirty(git_url):
if not allow_dirty and is_local_git_repo_dirty(git_url):
print_error(f"error: local git clone at {git_url} is dirty")
return False

Expand Down Expand Up @@ -549,7 +549,7 @@ def cmd_test(manager, args, config, configfile):
package_infos = []

for name in args.package:
if not check_local_git_repo(name):
if not check_local_git_repo(name, args.ignore_dirty_git):
sys.exit(1)

version = args.version if args.version else active_git_branch(name)
Expand Down Expand Up @@ -619,7 +619,7 @@ def cmd_install(manager, args, config, configfile):
package_infos = []

for name in args.package:
if not check_local_git_repo(name):
if not check_local_git_repo(name, args.ignore_dirty_git):
sys.exit(1)

version = args.version if args.version else active_git_branch(name)
Expand Down Expand Up @@ -889,7 +889,7 @@ def cmd_bundle(manager, args, config, configfile):
new_pkgs = []

for name, version in packages:
if not check_local_git_repo(name):
if not check_local_git_repo(name, args.ignore_dirty_git):
sys.exit(1)

if not version:
Expand Down Expand Up @@ -2471,6 +2471,13 @@ def argparser():
" the latest version tag, or if a package has none,"
' the default branch, like "main" or "master".',
)
sub_parser.add_argument(
"--ignore-dirty-git",
action="store_true",
help=(
"Allows installation of packages from 'dirty' git clones instead of failing."
),
)

# install
sub_parser = command_parser.add_parser(
Expand Down Expand Up @@ -2512,6 +2519,13 @@ def argparser():
" the latest version tag, or if a package has none,"
' the default branch, like "main" or "master".',
)
sub_parser.add_argument(
"--ignore-dirty-git",
action="store_true",
help=(
"Allows installation of packages from 'dirty' git clones instead of failing."
),
)
add_uservar_args(sub_parser)

# bundle
Expand Down Expand Up @@ -2569,6 +2583,13 @@ def argparser():
" left blank to indicate that the latest available version should be"
" used.",
)
sub_parser.add_argument(
"--ignore-dirty-git",
action="store_true",
help=(
"Allows installation of packages from 'dirty' git clones instead of failing."
),
)

# unbundle
sub_parser = command_parser.add_parser(
Expand Down

0 comments on commit ecf4c2e

Please sign in to comment.