Skip to content
Open
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
61 changes: 60 additions & 1 deletion obs_scm_bridge
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,55 @@ class ObsGit(object):
gsmpath[path] = section
self.gsmpath = gsmpath

def checkout_project(self, include_submodules: bool=False) -> None:
# clone project git without submodules by default
self.do_clone(self.outdir, include_submodules=include_submodules)
if self.onlybuild.keys():
self.clonedir = self.outdir
if os.path.isfile(self.outdir + '/.gitmodules'):
self.parse_gsmconfig()
# clone the selected packages by default
self.update_package_submodules('')

def update_package_submodules(self, subdir) -> None:
if subdir:
self.verify_subdir(subdir)
self.check_subdir(subdir)
directory = (self.outdir + '/' + subdir).rstrip('/')
logging.debug("check %s (subdir=%s)", directory, subdir)

packages = None
subdirectories = []

if os.path.isfile(directory + '/_manifest'):
print(" reading ", directory + '/_manifest')
(packages, subdirectories) = self.read_project_manifest(directory + '/_manifest')

# handle all subdirectories
for newsubdir in subdirectories:
if (subdir + newsubdir + '/') in self.processed:
continue
self.processed[subdir + newsubdir + '/'] = True
self.update_package_submodules(subdir + newsubdir + '/')

if packages is None or len(packages) == 0:
logging.debug("walk via %s", directory)
packages = sorted(os.listdir(directory))

# handle plain files and directories
for name in packages:
if name in self.processed:
continue # already handled
if self.onlybuild and name not in self.onlybuild.keys():
continue
fname = directory + '/' + name
if os.path.isdir(fname):
if (subdir + name) in self.gsmpath:
self.process_package_submodule(name, subdir)
cmd = [ 'git', '-C', outdir, 'submodule', 'update', '--init', subdir + name ]
self.run_cmd(cmd, fatal='submodule update')
self.processed[name] = True

def generate_project_files(self) -> None:
clonedir = tempfile.mkdtemp(prefix="obs-scm-bridge")
self.clonedir = clonedir
Expand Down Expand Up @@ -861,6 +910,8 @@ if __name__ == '__main__':
required=True,
nargs=1,
type=str)
parser.add_argument('--native-projectmode',
help='clone the project git without submodules. set it to recursive if you want all submodule sources')
Comment on lines +913 to +914

@dmach dmach May 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be nice to specify choices such as choices=['recursive', 'normal'].
I made normal up, maybe you have a better word for it.

BTW, how should I use it in obs? With recursive or without?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

'recursive' and 'flat' maybe ... good idea. Maybe even a third option "empty" to skip submodule cloning complete.
git-obs you mean? Good question, very large projects should maybe cloned only 'empty' by default, but this is a bit of a heuristic.

'recursive' should be only optional IMHO.

parser.add_argument('--projectmode',
help='just return the package list based on the subdirectories')
parser.add_argument('--projectscmsync',
Expand All @@ -871,6 +922,7 @@ if __name__ == '__main__':

url = args['url'][0]
outdir = args['outdir'][0]
native_project_mode = args['native_projectmode']
project_mode = args['projectmode']
projectscmsync = args['projectscmsync']

Expand All @@ -888,7 +940,14 @@ if __name__ == '__main__':
if os.path.isfile(credentials_config):
obsgit.setup_credentials(credentials_config)

if project_mode == 'true' or project_mode == '1':
if native_project_mode:
# create a git checkout structure for local work
obsgit.checkout_project(include_submodules=(native_project_mode == 'recursive'))
sys.exit(0)
elif project_mode == 'true' or project_mode == '1':
if not os.environ.get('OBS_SERVICE_DAEMON'):
obsgit.die("Please use --native-projectmode for getting a git repository")
# just create meta files for each package
obsgit.generate_project_files()
sys.exit(0)

Expand Down
Loading