diff --git a/behave/features/environment.py b/behave/features/environment.py index 352c1be0..a89b63a7 100644 --- a/behave/features/environment.py +++ b/behave/features/environment.py @@ -81,15 +81,16 @@ def before_all(context): context.podman = podman.ThreadedPodman(context, container_name_prefix="osc-behave-", max_containers=podman_max_containers) else: context.podman = podman.Podman(context, container_name="osc-behave") - context.osc = osc.Osc(context) context.git_obs = osc.GitObs(context) context.git_osc_precommit_hook = osc.GitOscPrecommitHook(context) + # we reference git_obs here, so initialize osc after it + context.osc = osc.Osc(context) def after_all(context): + del context.osc del context.git_osc_precommit_hook del context.git_obs - del context.osc context.podman.kill() del context.podman del context.fixtures diff --git a/behave/features/fork.feature b/behave/features/fork.feature new file mode 100644 index 00000000..26853d4b --- /dev/null +++ b/behave/features/fork.feature @@ -0,0 +1,12 @@ +Feature: `osc fork` command + + +Background: + Given I set working directory to "{context.osc.temp}" + +@destructive +Scenario: Fork a git repo + When I execute osc with args "fork test:factory test-GitPkgA" + Then the exit code is 0 + And stdout contains " scmsync URL: " + And stdout contains "/Admin/test-GitPkgA#factory" diff --git a/behave/features/steps/common.py b/behave/features/steps/common.py index 6e81af77..fef72192 100644 --- a/behave/features/steps/common.py +++ b/behave/features/steps/common.py @@ -64,11 +64,16 @@ def run_in_context(context, cmd, can_fail=False, **run_args): if hasattr(context.scenario, "working_dir") and 'cwd' not in run_args: run_args['cwd'] = context.scenario.working_dir + env = os.environ.copy() + # let's temporarily pass GIT_OBS_CONFIG through environment variable until other methods work + if not env.get("GIT_OBS_CONFIG"): + env["GIT_OBS_CONFIG"] = context.git_obs.config + if hasattr(context.scenario, "PATH"): - env = os.environ.copy() path = context.scenario.PATH env["PATH"] = path.replace("$PATH", env["PATH"]) - run_args["env"] = env + + run_args["env"] = env debug(context, "Running command:", cmd) diff --git a/behave/features/steps/osc.py b/behave/features/steps/osc.py index 20e4e9fb..32f6181d 100644 --- a/behave/features/steps/osc.py +++ b/behave/features/steps/osc.py @@ -47,6 +47,9 @@ class Osc(CommandBase): def write_config(self, username=None, password=None): with open(self.config, "w") as f: f.write("[general]\n") + # this doesn't work and as workaround initialize environment variable in steps/common.py + if self.context.git_obs.config: + f.write(f"gitea_config={self.context.git_obs.config}\n") f.write("\n") f.write(f"[https://localhost:{self.context.podman.container.ports['obs_https']}]\n") f.write(f"user={username or 'Admin'}\n") diff --git a/osc/commandline_common.py b/osc/commandline_common.py index 5bafd6c6..0c45447a 100644 --- a/osc/commandline_common.py +++ b/osc/commandline_common.py @@ -165,6 +165,9 @@ class Command: because it disables argument intermixing. """ + def post_parse_args(self, args): + pass + def run(self, args): """ Override to implement the command functionality. @@ -214,6 +217,7 @@ class MainCommand(Command): if not cmd: self.parser.error("Please specify a command") self.post_parse_args(args) + cmd.post_parse_args(args) return cmd.run(args) def load_command(self, cls, module_prefix): diff --git a/osc/gitea_api/conf.py b/osc/gitea_api/conf.py index 43d1fae0..b2c4e5d1 100644 --- a/osc/gitea_api/conf.py +++ b/osc/gitea_api/conf.py @@ -38,13 +38,16 @@ class Login(BaseModel): def __str__(self): if self.kwargs == {"name": None}: - return \ - "Could not find a default Gitea config entry\n" \ - " * either set the default entry by running `git-obs login edit --set-as-default`\n" \ + return ( + "Could not find a default Gitea config entry\n" + " * either set the default entry by running `git-obs login update --set-as-default`\n" " * or run the command with `-G/--gitea-login ` option" + ) kwargs_str = ", ".join([f"{key}={value}" for key, value in self.kwargs.items()]) - return f"Could not find a matching Gitea config entry: {kwargs_str}\n" \ + return ( + f"Could not find a matching Gitea config entry: {kwargs_str}\n" " * see `git-obs login list` for valid entries" + ) def __init__(self, **kwargs): # ignore extra fields