diff --git a/NEWS b/NEWS index d04585ec..1da87df9 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ 0.153 OBS 2.7 only: - add "addchannels" and "enablechannel" commands + - support new package instances on branching when using -N parameter 0.152 - add support searching for groups via "group:" prefix diff --git a/osc/commandline.py b/osc/commandline.py index 9c3eb14e..27420d56 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -3221,7 +3221,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. if len(args) >= 4: tpackage = args[3] - exists, targetprj, targetpkg, srcprj, srcpkg = \ + try: + exists, targetprj, targetpkg, srcprj, srcpkg = \ branch_pkg(apiurl, args[0], args[1], nodevelproject=opts.nodevelproject, rev=opts.revision, target_project=tproject, target_package=tpackage, @@ -3231,6 +3232,21 @@ Please submit there instead, or use --nodevelproject to force direct submission. extend_package_names=opts.extend_package_names, missingok=opts.new_package, maintenance=opts.maintenance) + except oscerr.NotMissing as e: + print('NOTE: Package target exists already via project links, link will point to given project.') + print(' A submission will initialize a new instance.') + exists, targetprj, targetpkg, srcprj, srcpkg = \ + branch_pkg(apiurl, args[0], args[1], + nodevelproject=opts.nodevelproject, rev=opts.revision, + target_project=tproject, target_package=tpackage, + return_existing=opts.checkout, msg=opts.message or '', + force=opts.force, noaccess=opts.noaccess, + add_repositories=opts.add_repositories, + extend_package_names=opts.extend_package_names, + missingok=False, + maintenance=opts.maintenance, + newinstance=opts.new_package) + if exists: print('Using existing branch project: %s' % targetprj, file=sys.stderr) diff --git a/osc/core.py b/osc/core.py index 36201512..d2b59c1e 100644 --- a/osc/core.py +++ b/osc/core.py @@ -4956,7 +4956,7 @@ def attribute_branch_pkg(apiurl, attribute, maintained_update_project_attribute, return r -def branch_pkg(apiurl, src_project, src_package, nodevelproject=False, rev=None, target_project=None, target_package=None, return_existing=False, msg='', force=False, noaccess=False, add_repositories=False, extend_package_names=False, missingok=False, maintenance=False): +def branch_pkg(apiurl, src_project, src_package, nodevelproject=False, rev=None, target_project=None, target_package=None, return_existing=False, msg='', force=False, noaccess=False, add_repositories=False, extend_package_names=False, missingok=False, maintenance=False, newinstance=False): """ Branch a package (via API call) """ @@ -4973,6 +4973,8 @@ def branch_pkg(apiurl, src_project, src_package, nodevelproject=False, rev=None, query['maintenance'] = "1" if missingok: query['missingok'] = "1" + if newinstance: + query['newinstance'] = "1" if extend_package_names: query['extend_package_names'] = "1" if rev: @@ -4987,9 +4989,12 @@ def branch_pkg(apiurl, src_project, src_package, nodevelproject=False, rev=None, try: f = http_POST(u) except HTTPError as e: + root = ET.fromstring(e.read()) + if missingok: + if root and root.get('code') == "not_missing": + raise oscerr.NotMissing("Package exists already via project link, but link will point to given project") if not return_existing: raise - root = ET.fromstring(e.read()) summary = root.find('summary') if summary is None: raise oscerr.APIError('unexpected response:\n%s' % ET.tostring(root, encoding=ET_ENCODING)) diff --git a/osc/oscerr.py b/osc/oscerr.py index 372d6462..559f80d1 100644 --- a/osc/oscerr.py +++ b/osc/oscerr.py @@ -68,6 +68,9 @@ class WrongOptions(OscBaseError): class NoWorkingCopy(OscBaseError): """Exception raised when directory is neither a project dir nor a package dir""" +class NotMissing(OscBaseError): + """Exception raised when link target should not exist, but it does""" + class WorkingCopyWrongVersion(OscBaseError): """Exception raised when working copy's .osc/_osclib_version doesn't match"""