From 0eb0fc5a9a877cf410bfb30fbcc8c0ea33f09efc Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 23 Sep 2025 13:01:17 +0200 Subject: [PATCH] Modify osc subcommands to error out if they don't work with git --- .../osc-commands-unsupported-git.feature | 312 ++++++++++++++++++ osc/commandline.py | 157 +++++++++ osc/store.py | 15 + 3 files changed, 484 insertions(+) create mode 100644 behave/features/osc-commands-unsupported-git.feature diff --git a/behave/features/osc-commands-unsupported-git.feature b/behave/features/osc-commands-unsupported-git.feature new file mode 100644 index 00000000..9622144e --- /dev/null +++ b/behave/features/osc-commands-unsupported-git.feature @@ -0,0 +1,312 @@ +Feature: Osc commands that do not support git + + +Background: + Given I set working directory to "{context.osc.temp}" + And I execute "git init -b factory" + And I execute git-obs with args "meta set --apiurl='https://localhost:{context.podman.container.ports[obs_https]}' --project=test:factory --package=new-package" + + +Scenario: Run 'osc add' + Given I create file "{context.osc.temp}/new-file" with perms "0644" + """ + """ + When I execute osc with args "add new-file" + Then the exit code is 1 + And stderr is + """ + Command 'osc add' is not supported with git. Use 'git add' instead. + """ + + +Scenario: Run 'osc addremove' + When I execute osc with args "addremove" + Then the exit code is 1 + And stderr is + """ + Command 'osc addremove' is not supported with git. Use 'git add' and 'git rm' instead. + """ + + +Scenario: Run 'osc branch' + When I execute osc with args "branch" + Then the exit code is 1 + And stderr is + """ + Command 'osc branch' is not supported with git. Use 'osc fork' or 'git-obs repo fork' instead. + """ + + +Scenario: Run 'osc checkout' to checkout a package in a git project + # turn the git repo into a project + Given I create file "{context.osc.temp}/_manifest" with perms "0644" + """ + """ + And I execute git-obs with args "meta set --package=" + When I execute osc with args "checkout package" + Then the exit code is 1 + And stderr is + """ + Command 'osc checkout' is not supported with git. Use 'git-obs repo clone' instead. + """ + + +Scenario: Run 'osc clean' + When I execute osc with args "clean" + Then the exit code is 1 + And stderr is + """ + Command 'osc clean' is not supported with git. Use 'git reset' instead. + """ + + +Scenario: Run 'osc commit' + When I execute osc with args "commit" + Then the exit code is 1 + And stderr is + """ + Command 'osc commit' is not supported with git. Use 'git commit' and 'git push' instead. + """ + + +Scenario: Run 'osc delete' + When I execute osc with args "delete" + Then the exit code is 1 + And stderr is + """ + Command 'osc delete' is not supported with git. Use 'git rm' instead. + """ + + +Scenario: Run 'osc deleterequest' + When I execute osc with args "deleterequest" + Then the exit code is 1 + And stderr is + """ + Command 'osc deleterequest' is not supported with git. + """ + + +Scenario: Run 'osc develproject' + When I execute osc with args "develproject" + Then the exit code is 1 + And stderr is + """ + Command 'osc develproject' is not supported with git. + """ + + +Scenario: Run 'osc diff' + When I execute osc with args "diff" + Then the exit code is 1 + And stderr is + """ + Command 'osc diff' is not supported with git. Use 'git diff' instead. + """ + + +Scenario: Run 'osc importsrcpkg' + When I execute osc with args "importsrcpkg package.src.rpm" + Then the exit code is 1 + And stderr is + """ + Command 'osc importsrcpkg' is not supported with git. + """ + + +Scenario: Run 'osc init' + When I execute osc with args "init test:factory" + Then the exit code is 1 + And stderr is + """ + Command 'osc init' is not supported with git. + """ + + +Scenario: Run 'osc linkpac' + When I execute osc with args "linkpac" + Then the exit code is 1 + And stderr is + """ + Command 'osc linkpac' is not supported with git. + """ + + +Scenario: Run 'osc linktobranch' + When I execute osc with args "linktobranch" + Then the exit code is 1 + And stderr is + """ + Command 'osc linktobranch' is not supported with git. + """ + + +Scenario: Run 'osc log' + When I execute osc with args "log" + Then the exit code is 1 + And stderr is + """ + Command 'osc log' is not supported with git. + """ + + +Scenario: Run 'osc maintainer' + When I execute osc with args "maintainer" + Then the exit code is 1 + And stderr is + """ + Command 'osc maintainer' is not supported with git. + """ + + +Scenario: Run 'osc maintenancerequest' + When I execute osc with args "maintenancerequest" + Then the exit code is 1 + And stderr is + """ + Command 'osc maintenancerequest' is not supported with git. + """ + + +Scenario: Run 'osc mkpac' + When I execute osc with args "mkpac" + Then the exit code is 1 + And stderr is + """ + Command 'osc mkpac' is not supported with git. Add a submodule with a package instead. + """ + + +Scenario: Run 'osc mv' + When I execute osc with args "mv old-file new-file" + Then the exit code is 1 + And stderr is + """ + Command 'osc mv' is not supported with git. Use 'git mv' instead. + """ + + +Scenario: Run 'osc pdiff' + When I execute osc with args "pdiff" + Then the exit code is 1 + And stderr is + """ + Command 'osc pdiff' is not supported with git. + """ + + +Scenario: Run 'osc pull' + When I execute osc with args "pull" + Then the exit code is 1 + And stderr is + """ + Command 'osc pull' is not supported with git. Use 'git fetch' and 'git rebase' instead. + """ + + +Scenario: Run 'osc releaserequest' + When I execute osc with args "releaserequest" + Then the exit code is 1 + And stderr is + """ + Command 'osc releaserequest' is not supported with git. + """ + + +Scenario: Run 'osc repairlink' + When I execute osc with args "repairlink" + Then the exit code is 1 + And stderr is + """ + Command 'osc repairlink' is not supported with git. + """ + + +Scenario: Run 'osc repairwc' + When I execute osc with args "repairwc" + Then the exit code is 1 + And stderr is + """ + Command 'osc repairwc' is not supported with git. + """ + + +Scenario: Run 'osc requestmaintainership' + When I execute osc with args "requestmaintainership" + Then the exit code is 1 + And stderr is + """ + Command 'osc requestmaintainership' is not supported with git. + """ + + +Scenario: Run 'osc resolved' + When I execute osc with args "resolved" + Then the exit code is 1 + And stderr is + """ + Command 'osc resolved' is not supported with git. + """ + + +Scenario: Run 'osc revert' + When I execute osc with args "revert changed-file" + Then the exit code is 1 + And stderr is + """ + Command 'osc revert' is not supported with git. Use 'git checkout' instead. + """ + + +Scenario: Run 'osc setdevelproject' + When I execute osc with args "setdevelproject" + Then the exit code is 1 + And stderr is + """ + Command 'osc setdevelproject' is not supported with git. + """ + + +Scenario: Run 'osc setlinkrev' + When I execute osc with args "setlinkrev" + Then the exit code is 1 + And stderr is + """ + Command 'osc setlinkrev' is not supported with git. + """ + + +Scenario: Run 'osc status' + When I execute osc with args "status" + Then the exit code is 1 + And stderr is + """ + Command 'osc status' is not supported with git. User 'git status' instead. + """ + + +Scenario: Run 'osc submitrequest' + When I execute osc with args "submitrequest" + Then the exit code is 1 + And stderr is + """ + Command 'osc submitrequest' is not supported with git. Use 'git-obs pr create' instead. + """ + + +Scenario: Run 'osc update' + When I execute osc with args "update" + Then the exit code is 1 + And stderr is + """ + Command 'osc update' is not supported with git. + """ + + +Scenario: Run 'osc updatepacmetafromspec' + When I execute osc with args "updatepacmetafromspec" + Then the exit code is 1 + And stderr is + """ + Command 'osc updatepacmetafromspec' is not supported with git. + """ diff --git a/osc/commandline.py b/osc/commandline.py index 78996792..f292dbbe 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -875,6 +875,10 @@ class Osc(cmdln.Cmdln): from .core import show_files_meta from .core import show_scmsync from .core import store_write_string + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) project = opts.project package = opts.package @@ -1319,6 +1323,11 @@ class Osc(cmdln.Cmdln): """ from .core import show_devel_project + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) apiurl = self.get_api_url() @@ -1365,6 +1374,11 @@ class Osc(cmdln.Cmdln): """ from .core import set_devel_project + from .store import git_is_unsupported + + if len(args) <= 1: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) apiurl = self.get_api_url() @@ -1987,6 +2001,11 @@ class Osc(cmdln.Cmdln): from .core import show_devel_project from .core import slash_split from .core import store_read_project + from .store import git_is_unsupported + + if len(args) <= 2: + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git-obs pr create' instead." + git_is_unsupported(".", msg) def _check_service(root): serviceinfo = root.find('serviceinfo') @@ -2750,6 +2769,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import slash_split from .core import store_read_package from .core import store_read_project + from .store import git_is_unsupported + + if len(args) <= 1: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) args = slash_split(args) apiurl = self.get_api_url() @@ -2838,6 +2862,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import slash_split from .core import store_read_package from .core import store_read_project + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) args = slash_split(args) @@ -3583,6 +3612,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import meta_get_packagelist from .core import parseRevisionOption from .core import set_link_rev + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) apiurl = self.get_api_url() @@ -3640,6 +3674,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import Package from .core import link_to_branch + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) apiurl = self.get_api_url() @@ -3678,6 +3717,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import delete_files from .core import show_files_meta from .core import show_package_meta + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) apiurl = self.get_api_url() @@ -3750,6 +3794,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import link_pac from .core import parseRevisionOption from .core import show_upstream_rev_vrev + from .store import git_is_unsupported + + if len(args) <= 2: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) apiurl = self.get_api_url() @@ -4004,6 +4053,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import show_project_meta from .core import slash_split from .core import store_read_project + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) # FIXME: additional parameters can be a certain repo list to create a partitial release @@ -4164,6 +4218,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import slash_split from .core import store_read_package from .core import store_read_project + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) args = slash_split(args) apiurl = self.get_api_url() @@ -4453,6 +4512,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import slash_split from .core import store_read_package from .core import store_read_project + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'osc fork' or 'git-obs repo fork' instead." + git_is_unsupported(".", msg) if subcmd in ('getpac', 'branchco', 'bco'): opts.checkout = True @@ -4697,6 +4761,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import Package from .core import parseargs + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) args = parseargs(args) if opts.specfile and len(args) == 1: @@ -4759,6 +4827,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import run_pager from .core import server_diff from .core import server_diff_noex + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git diff' instead." + git_is_unsupported(".", msg) if (subcmd in ('ldiff', 'linkdiff')): opts.link = True @@ -5053,6 +5125,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import slash_split from .core import store_read_package from .core import store_read_project + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) apiurl = self.get_api_url() args = slash_split(args) @@ -5438,6 +5515,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import slash_split from .core import statfrmt from .core import store_read_project + from .store import git_is_unsupported if opts.unexpand_link: expand_link = False @@ -5473,6 +5551,9 @@ Please submit there instead, or use --nodevelproject to force direct submission. pass if len(args) == 1 and is_project_dir(Path.cwd()): + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git-obs repo clone' instead." + git_is_unsupported(".", msg) + project = store_read_project(Path.cwd()) project_dir = Path.cwd() package = args[0] @@ -5612,6 +5693,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import is_project_dir from .core import parseargs from .core import statfrmt + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. User 'git status' instead." + git_is_unsupported(".", msg) args = parseargs(args) lines = [] @@ -5668,6 +5753,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import addFiles from .core import addGitSource from .core import parseargs + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git add' instead." + git_is_unsupported(".", msg) if not args: self.argparse_error("Incorrect number of arguments.") @@ -5694,6 +5783,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from . import conf from .core import createPackageDir + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Add a submodule with a package instead." + git_is_unsupported(".", msg) if not conf.config['do_package_tracking']: print("to use this feature you have to enable \'do_package_tracking\' " @@ -5726,6 +5819,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import is_project_dir from .core import parseargs from .core import statfrmt + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git add' and 'git rm' instead." + git_is_unsupported(".", msg) args = parseargs(args) arg_list = args[:] @@ -5826,6 +5923,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import parseargs from .core import raw_input from .core import store_unlink_file + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git commit' and 'git push' instead." + git_is_unsupported(".", msg) args = parseargs(args) @@ -6004,6 +6105,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import print_request_list from .core import show_files_meta from .core import show_upstream_rev + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) if opts.expand_link and opts.unexpand_link: raise oscerr.WrongOptions('Sorry, the options --expand-link and ' @@ -6139,6 +6244,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import is_project_dir from .core import parseargs from .core import statfrmt + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git rm' instead." + git_is_unsupported(".", msg) if not args: self.argparse_error("Incorrect number of arguments.") @@ -6207,6 +6316,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import Package from .core import parseargs + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) if not args: self.argparse_error("Incorrect number of arguments.") @@ -8193,6 +8306,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import parseRevisionOption from .core import revision_is_empty from .output import pipe_to_pager + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) apiurl = self.get_api_url() @@ -9360,8 +9478,12 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import store_read_project from .core import unpack_srcrpm from .grabber import OscFileGrabber + from .store import git_is_unsupported from .util import rpmquery + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) + srpm = opts.srpm if opts.delete_old_files and conf.config['do_package_tracking']: @@ -9617,6 +9739,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import slash_split from .core import store_read_package from .core import store_read_project + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) def get_maintainer_data(apiurl, maintainer, verbose=False): tags = ('email',) @@ -9922,6 +10049,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import is_package_dir from .core import is_project_dir from .core import store_read_project + from .store import get_store apiurl = self.get_api_url() project = None @@ -9977,6 +10105,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import store_read_package from .core import store_read_project from .core import streamfile + from .store import git_is_unsupported if len(args) == 1 and (args[0].startswith('http://') or args[0].startswith('https://')): @@ -9993,6 +10122,9 @@ Please submit there instead, or use --nodevelproject to force direct submission. package = args[1] filename = args[2] elif len(args) == 1 and is_package_dir(Path.cwd()): + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git show :' instead." + git_is_unsupported(".", msg) + project = store_read_project(Path.cwd()) package = store_read_package(Path.cwd()) filename = args[0] @@ -10075,6 +10207,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import store_read_package from .core import store_read_project from .core import store_write_string + from .store import git_is_unsupported + + if not args: + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) apiurl = self.get_api_url() args = slash_split(args) @@ -10264,6 +10401,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import run_external from .core import statfrmt from .core import store_write_string + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git fetch' and 'git rebase' instead." + git_is_unsupported(".", msg) p = Package('.') # check if everything is committed @@ -10596,6 +10737,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. """ from .core import Package + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git mv' instead." + git_is_unsupported(".", msg) source = opts.source dest = opts.dest @@ -10739,6 +10884,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. """ from .core import Package + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git checkout' instead." + git_is_unsupported(".", msg) files = opts.file pacs = Package.from_paths(files) @@ -10771,6 +10920,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import parseargs from .core import raw_input from .store import Store + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git." + git_is_unsupported(".", msg) def get_apiurl(apiurls): print('No apiurl is defined for this working copy.\n' @@ -10848,6 +11001,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. from .core import getTransActPath from .core import is_package_dir from .core import parseargs + from .store import git_is_unsupported + + msg = f"Command 'osc {subcmd}' is not supported with git. Use 'git reset' instead." + git_is_unsupported(".", msg) pacs = parseargs(args) # do a sanity check first diff --git a/osc/store.py b/osc/store.py index c6f547bc..c2dae530 100644 --- a/osc/store.py +++ b/osc/store.py @@ -43,3 +43,18 @@ def get_store(path, check=True, print_warnings=False): raise oscerr.NoWorkingCopy(msg) return store + + +def git_is_unsupported(path: str, msg: str): + store = None + try: + store = get_store(path) + except oscerr.NoWorkingCopy: + pass + + if not store: + # not a working copy, we're not handling it + return + + if isinstance(store, git_scm.GitStore) or store.scmurl: + raise oscerr.NoWorkingCopy(msg)