def main(argv): retval = 0 (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: current = repo.get_branch() if action == "export": export_patches(repo, current, options) elif action == "import": import_pq(repo, current, options) elif action == "drop": drop_pq(repo, current) elif action == "rebase": rebase_pq(repo, current, options) elif action == "apply": patch = Patch(patchfile) maintainer = get_maintainer_from_control(repo) apply_single_patch(repo, current, patch, maintainer, options.topic) elif action == "switch": switch_pq(repo, current, options) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 return retval
def main(argv): retval = 0 source = None options, args = parse_args(argv, '') if args or not options: return ExitCodes.parse_error try: repo = DebianGitRepository(os.path.curdir, toplevel=False) except GitRepositoryError: gbp.log.err("%s is not inside a git repository" % (os.path.abspath('.'))) return 1 try: try: source = DebianSource(repo.path) source.is_native() except Exception as e: raise GbpError("Can't determine package type: %s" % e) if options.tarball_dir and source.upstream_version is not None: options.tarball_dir = PkgPolicy.version_subst(options.tarball_dir, source.upstream_version) output_dir = options.tarball_dir or os.path.join(repo.path, '..') if source.is_native(): gbp.log.info("Nothing to be done for native package") return 0 prepare_upstream_tarballs(repo, source, options, output_dir, output_dir) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 except DebianSourceError as err: gbp.log.err(err) source = None retval = 1 return retval
def main(argv): ret = 1 repo = None (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error if len(args) != 2 or args[0] not in ['commit']: gbp.log.err("No action given") return 1 else: tarball = args[1] try: try: repo = DebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) debsource = DebianSource('.') # FIXME: this should be a single call sources = [DebianUpstreamSource(tarball)] sources += get_component_tarballs(debsource.sourcepkg, debsource.upstream_version, sources[0].path, options.components) upstream_tag = repo.version_to_tag(options.upstream_tag, debsource.upstream_version) repo.create_pristine_tar_commits(upstream_tag, sources) ret = 0 except (GitRepositoryError, GbpError, CommandExecFailed) as err: if str(err): gbp.log.err(err) except KeyboardInterrupt: gbp.log.err("Interrupted. Aborting.") if not ret: comp_msg = (' with additional tarballs for %s' % ", ".join([os.path.basename(t.path) for t in sources[1:]])) if sources[1:] else '' gbp.log.info( "Successfully committed pristine-tar data for version %s of %s%s" % (debsource.version, tarball, comp_msg)) return ret
def upstream_version(self): """ Find the upstream version we just imported. git-buildpackage import-orig will generate this "upstream" tag automatically, and we can use it to discover the version of the current branch. It uses git-describe, like so: git describe --match 'upstream/*' --abbrev=0 (Note: this method is similar to gbp.deb.git.DebianGitRepository debian_version_from_upstream(), but that appends the debian release number "-1", and we don't want that here.) """ repo = DebianGitRepository('.') tag = repo.find_branch_tag('HEAD', 'HEAD', pattern='upstream/*') # should we get tagformat from GbpOptionParser instead of hardcoding? tagformat = "upstream/%(version)s" return repo.tag_to_version(tag, tagformat)
def main(argv): ret = 0 repo = None (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error if len(args) != 2 or args[0] not in ['commit']: gbp.log.err("No action given") return 1 else: tarball = args[1] try: try: repo = DebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) source = DebianSource('.') component_tarballs = get_component_tarballs(source.sourcepkg, source.upstream_version, tarball, options.components) upstream_tag = repo.version_to_tag(options.upstream_tag, source.upstream_version) repo.create_pristine_tar_commits(upstream_tag, tarball, component_tarballs) except (GitRepositoryError, GbpError, CommandExecFailed) as err: if str(err): gbp.log.err(err) ret = 1 if not ret: comp_msg = (' with additional tarballs for %s' % ", ".join( [os.path.basename(t[1]) for t in component_tarballs])) if component_tarballs else '' gbp.log.info( "Successfully committed pristine-tar data for version %s of %s%s" % (source.upstream_version, tarball, comp_msg)) return ret
def main(argv): retval = 1 (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) try: repo = DebianGitRepository(os.path.curdir, toplevel=False) except GitRepositoryError: gbp.log.err("%s is not inside a git repository" % (os.path.abspath('.'))) return 1 try: source = DebianSource(repo.path) if not (options.ignore_branch or options.ignore_new): if repo.branch != options.debian_branch: gbp.log.err( "You are not on branch '%s' but on '%s'" % (options.debian_branch, repo.branch or 'no branch')) raise GbpError("Use --ignore-branch to ignore or " "--debian-branch to set the branch name.") if not options.ignore_new: (ret, out) = repo.is_clean() if not ret: gbp.log.err( "You have uncommitted changes in your source tree:") gbp.log.err(out) raise GbpError("Use --ignore-new to ignore.") perform_tagging(repo, source, options) retval = 0 except (GbpError, GitRepositoryError, DebianSourceError) as err: if str(err): gbp.log.err(err) except KeyboardInterrupt: gbp.log.err("Interrupted. Aborting.") return retval
def main(argv): repo = None (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error try: try: repo = DebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) if not options.attr_presets: raise GbpError("Nothing to do, no settings to apply.") setup_gitattributes(repo) except (GitRepositoryError, GbpError, CommandExecFailed) as err: if str(err): gbp.log.err(err) except KeyboardInterrupt: gbp.log.err("Interrupted. Aborting.") return 0
def main(argv): retval = 0 current = None rem_repo = None (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) == 2: rem_repo = args[1] gbp.log.info("Fetching from '%s'" % rem_repo) else: gbp.log.info("Fetching from default remote for each branch") try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: branches = [] try: current = repo.get_branch() except GitRepositoryError: # Not being on any branch is o.k. with --git-ignore-branch if options.ignore_branch: current = repo.head gbp.log.info("Found detached head at '%s'" % current) else: raise for branch in [options.debian_branch, options.upstream_branch]: if repo.has_branch(branch): branches += [branch] if repo.has_pristine_tar_branch() and options.pristine_tar: branches += [repo.pristine_tar_branch] (ret, out) = repo.is_clean() if not ret: gbp.log.err("You have uncommitted changes in your source tree:") gbp.log.err(out) raise GbpError repo.fetch(rem_repo, depth=options.depth) repo.fetch(rem_repo, depth=options.depth, tags=True) for branch in branches: if not fast_forward_branch(rem_repo, branch, repo, options): retval = 2 if options.redo_pq: repo.set_branch(options.debian_branch) Command("gbp-pq")(["drop"]) Command("gbp-pq")(["import"]) repo.set_branch(current) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 return retval
def main(argv): ret = 0 tmpdir = '' pristine_orig = None linked = False (options, args) = parse_args(argv) if not options: return 1 try: source = find_source(options.uscan, args) if not source: return ret try: repo = DebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) # an empty repo has now branches: initial_branch = repo.get_branch() is_empty = False if initial_branch else True if not repo.has_branch(options.upstream_branch) and not is_empty: raise GbpError(no_upstream_branch_msg % options.upstream_branch) (sourcepackage, version) = detect_name_and_version(repo, source, options) (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err("Repository has uncommitted changes, commit these first: ") raise GbpError(out) if repo.bare: set_bare_repo_options(options) if not source.is_dir(): tmpdir = tempfile.mkdtemp(dir='../') source.unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked)) if source.needs_repack(options): gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked)) (source, tmpdir) = repack_source(source, sourcepackage, version, tmpdir, options.filters) (pristine_orig, linked) = prepare_pristine_tar(source.path, sourcepackage, version) # Don't mess up our repo with git metadata from an upstream tarball try: if os.path.isdir(os.path.join(source.unpacked, '.git/')): raise GbpError("The orig tarball contains .git metadata - giving up.") except OSError: pass try: upstream_branch = [ options.upstream_branch, 'master' ][is_empty] filter_msg = ["", " (filtering out %s)" % options.filters][len(options.filters) > 0] gbp.log.info("Importing '%s' to branch '%s'%s..." % (source.path, upstream_branch, filter_msg)) gbp.log.info("Source package is %s" % sourcepackage) gbp.log.info("Upstream version is %s" % version) import_branch = [ options.upstream_branch, None ][is_empty] msg = upstream_import_commit_msg(options, version) if options.vcs_tag: parents = [repo.rev_parse("%s^{}" % options.vcs_tag)] else: parents = None commit = repo.commit_dir(source.unpacked, msg=msg, branch=import_branch, other_parents=parents, ) if options.pristine_tar: if pristine_orig: repo.pristine_tar.commit(pristine_orig, upstream_branch) else: gbp.log.warn("'%s' not an archive, skipping pristine-tar" % source.path) tag = repo.version_to_tag(options.upstream_tag, version) repo.create_tag(name=tag, msg="Upstream version %s" % version, commit=commit, sign=options.sign_tags, keyid=options.keyid) if is_empty: repo.create_branch(options.upstream_branch, rev=commit) repo.force_head(options.upstream_branch, hard=True) elif options.merge: gbp.log.info("Merging to '%s'" % options.debian_branch) repo.set_branch(options.debian_branch) try: repo.merge(tag) except GitRepositoryError: raise GbpError("Merge failed, please resolve.") if options.postimport: epoch = '' if os.access('debian/changelog', os.R_OK): # No need to check the changelog file from the # repository, since we're certain that we're on # the debian-branch cp = ChangeLog(filename='debian/changelog') if cp.has_epoch(): epoch = '%s:' % cp.epoch info = { 'version': "%s%s-1" % (epoch, version) } env = { 'GBP_BRANCH': options.debian_branch } gbpc.Command(options.postimport % info, extra_env=env, shell=True)() # Update working copy and index if we've possibly updated the # checked out branch current_branch = repo.get_branch() if current_branch in [ options.upstream_branch, repo.pristine_tar_branch]: repo.force_head(current_branch, hard=True) except (gbpc.CommandExecFailed, GitRepositoryError) as err: msg = err.__str__() if len(err.__str__()) else '' raise GbpError("Import of %s failed: %s" % (source.path, msg)) except GbpError as err: if len(err.__str__()): gbp.log.err(err) ret = 1 if pristine_orig and linked and not options.symlink_orig: os.unlink(pristine_orig) if tmpdir: cleanup_tmp_tree(tmpdir) if not ret: gbp.log.info("Successfully imported version %s of %s" % (version, source.path)) return ret
def main(argv): ret = 0 changelog = 'debian/changelog' until = 'HEAD' found_snapshot_banner = False version_change = {} branch = None options, args, dch_options, editor_cmd = parse_args(argv) try: try: repo = DebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) try: branch = repo.get_branch() except GitRepositoryError: # Not being on any branch is o.k. with --ignore-branch if not options.ignore_branch: raise if options.packaging_branch != branch and not options.ignore_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.packaging_branch, branch)) raise GbpError("Use --ignore-branch to ignore or --debian-branch " "to set the branch name.") source = DebianSource('.') cp = source.changelog if options.since: since = options.since else: since = '' if options.auto: since = guess_documented_commit(cp, repo, options.packaging_tag) if since: msg = "Continuing from commit '%s'" % since else: msg = "Starting from first commit" gbp.log.info(msg) found_snapshot_banner = has_snapshot_banner(cp) else: # Fallback: continue from last tag since = repo.find_version(options.packaging_tag, cp['Version']) if not since: raise GbpError("Version %s not found" % cp['Version']) if args: gbp.log.info("Only looking for changes on '%s'" % " ".join(args)) commits = repo.get_commits(since=since, until=until, paths=args, options=options.git_log.split(" ")) commits.reverse() # add a new changelog section if: if (options.new_version or options.bpo or options.nmu or options.qa or options.team or options.security): if options.bpo: version_change['increment'] = '--bpo' elif options.nmu: version_change['increment'] = '--nmu' elif options.qa: version_change['increment'] = '--qa' elif options.team: version_change['increment'] = '--team' elif options.security: version_change['increment'] = '--security' else: version_change['version'] = options.new_version # the user wants to force a new version add_section = True elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner and commits: # the last version was a release and we have pending commits add_section = True elif options.snapshot and not found_snapshot_banner: # the user want to switch to snapshot mode add_section = True else: add_section = False if add_section and not version_change and not source.is_native(): # Get version from upstream if none provided v = guess_version_from_upstream(repo, options.upstream_tag, cp) if v: version_change['version'] = v i = 0 for c in commits: i += 1 parsed = parse_commit(repo, c, options, last_commit=i == len(commits)) commit_msg, (commit_author, commit_email) = parsed if not commit_msg: # Some commits can be ignored continue if add_section: # Add a section containing just this message (we can't # add an empty section with dch) cp.add_section(distribution="UNRELEASED", msg=commit_msg, version=version_change, author=commit_author, email=commit_email, dch_options=dch_options) # Adding a section only needs to happen once. add_section = False else: cp.add_entry(commit_msg, commit_author, commit_email, dch_options) # Show a message if there were no commits (not even ignored # commits). if not commits: gbp.log.info("No changes detected from %s to %s." % (since, until)) if add_section: # If we end up here, then there were no commits to include, # so we put a dummy message in the new section. cp.add_section(distribution="UNRELEASED", msg=["UNRELEASED"], version=version_change, dch_options=dch_options) fixup_section(repo, use_git_author=options.use_git_author, options=options, dch_options=dch_options) if options.release: do_release(changelog, repo, cp, use_git_author=options.use_git_author, dch_options=dch_options) elif options.snapshot: (snap, version) = do_snapshot(changelog, repo, options.snapshot_number) gbp.log.info("Changelog has been prepared for snapshot #%d at %s" % (snap, version)) if editor_cmd: gbpc.Command(editor_cmd, ["debian/changelog"])() if options.commit: # Get the version from the changelog file (since dch might # have incremented it, there's no way we can already know # the version). version = ChangeLog(filename=changelog).version # Commit the changes to the changelog file msg = changelog_commit_msg(options, version) repo.commit_files([changelog], msg) gbp.log.info("Changelog has been committed for version %s" % version) except (gbpc.CommandExecFailed, GbpError, GitRepositoryError, DebianSourceError, NoChangeLogError) as err: if len(err.__str__()): gbp.log.err(err) ret = 1 return ret
def main(argv): dirs = dict(top=os.path.abspath(os.curdir)) needs_repo = False ret = 1 skipped = False options, pkg, target = parse_all(argv) if not options: return ExitCodes.parse_error try: try: repo = DebianGitRepository('.') # remember if the was repo initially empty repo.empty = repo.is_empty() (clean, out) = repo.is_clean() if not clean and not repo.empty: raise GbpError( "Repository has uncommitted changes, commit these first: %s" % out) except GitRepositoryError: # no repo found, create one needs_repo = True if options.download: dscfile = download_source(pkg, dirs=dirs, unauth=options.allow_unauthenticated) else: dscfile = pkg dsc = DscFile.parse(dscfile) if dsc.pkgformat not in ['1.0', '3.0']: raise GbpError("Importing %s source format not yet supported." % dsc.pkgformat) if options.verbose: print_dsc(dsc) if needs_repo: target = target or dsc.pkg if os.path.exists(target): raise GbpError( "Directory '%s' already exists. If you want to import into it, " "please change into this directory otherwise move it away first." % target) gbp.log.info("No git repository found, creating one.") repo = DebianGitRepository.create(target) repo.empty = True os.chdir(repo.path) repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo) if repo.bare: disable_pristine_tar(options, "Bare repository") # unpack dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..')) source = DebianUpstreamSource(dsc.tgz) source.unpack(dirs['tmp'], options.filters) for (component, tarball) in dsc.additional_tarballs.items(): gbp.log.info("Found component tarball '%s'" % os.path.basename(tarball)) unpack_component_tarball(source.unpacked, component, tarball, options.filters) if repo.find_version(options.debian_tag, dsc.version): gbp.log.warn("Version %s already imported." % dsc.version) if options.allow_same_version: gbp.log.info("Moving tag of version '%s' since import forced" % dsc.version) move_tag_stamp(repo, options.debian_tag, dsc.version) else: raise SkipImport # import if dsc.native: import_native(repo, source, dsc, options) else: imported = False commit = repo.find_version(options.upstream_tag, dsc.upstream_version) if not repo.find_version(options.upstream_tag, dsc.upstream_version): commit = import_upstream(repo, source, dsc, options) imported = True if not repo.has_branch(options.debian_branch): if options.create_missing_branches: repo.create_branch(options.debian_branch, commit) else: raise GbpError( "Branch %s does not exist, use --create-missing-branches" % options.debian_branch) if dsc.diff or dsc.deb_tgz: apply_debian_patch(repo, source, dsc, commit, options) else: gbp.log.warn("Didn't find a diff to apply.") if imported and options.pristine_tar: repo.create_pristine_tar_commits( commit, dsc.tgz, dsc.additional_tarballs.items()) if repo.get_branch() == options.debian_branch or repo.empty: # Update HEAD if we modified the checked out branch repo.force_head(options.debian_branch, hard=True) ret = 0 except KeyboardInterrupt: gbp.log.err("Interrupted. Aborting.") except gbpc.CommandExecFailed: pass # command itself printed an error except GitRepositoryError as msg: gbp.log.err("Git command failed: %s" % msg) except GbpError as err: if str(err): gbp.log.err(err) except SkipImport: skipped = True ret = 0 finally: os.chdir(dirs['top']) for d in ['tmp', 'download']: if d in dirs: gbpc.RemoveTree(dirs[d])() if not ret and not skipped: gbp.log.info("Version '%s' imported under '%s'" % (dsc.version, repo.path)) return ret
def main(argv): retval = 0 prefix = "git-" source = None branch = None hook_env = {} options, gbp_args, dpkg_args = parse_args(argv, prefix) if not options: return ExitCodes.parse_error try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: clean_working_tree(options, repo) try: branch = repo.get_branch() except GitRepositoryError: # Not being on any branch is o.k. with --git-ignore-branch if not options.ignore_branch: raise if not options.ignore_new and not options.ignore_branch: if branch != options.debian_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch)) raise GbpError( "Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name." ) head = repo.head tree = write_tree(repo, options) source = source_vfs(repo, options, tree) check_tag(options, repo, source) if not options.tag_only: output_dir = prepare_output_dir(options.export_dir) tarball_dir = options.tarball_dir or output_dir # Get/build the upstream tarball if necessary. We delay this in # case of a postexport hook so the hook gets a chance to modify the # sources and create different tarballs (#640382) # We don't delay it in general since we want to fail early if the # tarball is missing. if not source.is_native(): if options.postexport: gbp.log.info( "Postexport hook set, delaying tarball creation") else: prepare_upstream_tarball(repo, source, options, tarball_dir, output_dir) build_env, hook_env = setup_pbuilder(options, repo, source.is_native()) # Export to another build dir if requested: if options.export_dir: tmp_dir = os.path.join(output_dir, "%s-tmp" % source.sourcepkg) export_source(repo, tree, source, options, tmp_dir, output_dir) # Run postexport hook if options.postexport: Hook('Postexport', options.postexport, extra_env=Hook.md(hook_env, { 'GBP_GIT_DIR': repo.git_dir, 'GBP_TMP_DIR': tmp_dir }))(dir=tmp_dir) major = (source.debian_version if source.is_native() else source.upstream_version) export_dir = os.path.join(output_dir, "%s-%s" % (source.sourcepkg, major)) gbp.log.info("Moving '%s' to '%s'" % (tmp_dir, export_dir)) move_old_export(export_dir) os.rename(tmp_dir, export_dir) # Delayed tarball creation in case a postexport hook is used: if not source.is_native() and options.postexport: prepare_upstream_tarball(repo, source, options, tarball_dir, output_dir) build_dir = export_dir else: build_dir = repo.path if options.prebuild: Hook('Prebuild', options.prebuild, extra_env=Hook.md(hook_env, { 'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': build_dir }))(dir=build_dir) # Finally build the package: RunAtCommand( options.builder, [pipes.quote(arg) for arg in dpkg_args], shell=True, extra_env=Hook.md(build_env, {'GBP_BUILD_DIR': build_dir}))(dir=build_dir) if options.postbuild: changes = os.path.abspath( "%s/../%s_%s_%s.changes" % (build_dir, source.changelog.name, source.changelog.noepoch, changes_file_suffix(dpkg_args))) gbp.log.debug("Looking for changes file %s" % changes) Hook('Postbuild', options.postbuild, extra_env=Hook.md(hook_env, { 'GBP_CHANGES_FILE': changes, 'GBP_BUILD_DIR': build_dir }))() if options.tag or options.tag_only: if is_pq_branch(branch): commit = repo.get_merge_base(branch, pq_branch_base(branch)) else: commit = head tag = repo.version_to_tag(options.debian_tag, source.version) gbp.log.info("Tagging %s as %s" % (source.version, tag)) if options.retag and repo.has_tag(tag): repo.delete_tag(tag) tag_msg = format_str( options.debian_tag_msg, dict(pkg=source.sourcepkg, version=source.version)) repo.create_tag(name=tag, msg=tag_msg, sign=options.sign_tags, commit=commit, keyid=options.keyid) if options.posttag: sha = repo.rev_parse("%s^{}" % tag) Hook('Posttag', options.posttag, extra_env=Hook.md( hook_env, { 'GBP_TAG': tag, 'GBP_BRANCH': branch or '(no branch)', 'GBP_SHA1': sha }))() except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 except DebianSourceError as err: gbp.log.err(err) source = None retval = 1 finally: drop_index(repo) if not options.tag_only: if options.export_dir and options.purge and not retval: RemoveTree(export_dir)() if source: summary, msg = gbp.notifications.build_msg(source.changelog, not retval) if not gbp.notifications.notify(summary, msg, options.notify): gbp.log.err("Failed to send notification") retval = 1 return retval
def main(argv): retval = 0 prefix = "git-" source = None branch = None options, gbp_args, dpkg_args = parse_args(argv, prefix) if not options: return 1 try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 else: repo_dir = os.path.abspath(os.path.curdir) try: Command(options.cleaner, shell=True)() if not options.ignore_new: (ret, out) = repo.is_clean() if not ret: gbp.log.err( "You have uncommitted changes in your source tree:") gbp.log.err(out) raise GbpError("Use --git-ignore-new to ignore.") try: branch = repo.get_branch() except GitRepositoryError: # Not being on any branch is o.k. with --git-ignore-branch if not options.ignore_branch: raise if not options.ignore_new and not options.ignore_branch: if branch != options.debian_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch)) raise GbpError( "Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name." ) tree = write_tree(repo, options) source = source_vfs(repo, options, tree) if not options.tag_only: output_dir = prepare_output_dir(options.export_dir) tarball_dir = options.tarball_dir or output_dir # Get/build the upstream tarball if necessary. We delay this in # case of a postexport hook so the hook gets a chance to modify the # sources and create different tarballs (#640382) # We don't delay it in general since we want to fail early if the # tarball is missing. if not source.is_native(): if options.postexport: gbp.log.info( "Postexport hook set, delaying tarball creation") else: prepare_upstream_tarball(repo, source.changelog, options, tarball_dir, output_dir) # Export to another build dir if requested: if options.export_dir: tmp_dir = os.path.join(output_dir, "%s-tmp" % source.sourcepkg) export_source(repo, tree, source, options, tmp_dir, output_dir) # Run postexport hook if options.postexport: RunAtCommand(options.postexport, shell=True, extra_env={ 'GBP_GIT_DIR': repo.git_dir, 'GBP_TMP_DIR': tmp_dir })(dir=tmp_dir) major = (source.changelog.debian_version if source.is_native() else source.changelog.upstream_version) export_dir = os.path.join(output_dir, "%s-%s" % (source.sourcepkg, major)) gbp.log.info("Moving '%s' to '%s'" % (tmp_dir, export_dir)) move_old_export(export_dir) os.rename(tmp_dir, export_dir) # Delayed tarball creation in case a postexport hook is used: if not source.is_native() and options.postexport: prepare_upstream_tarball(repo, source.changelog, options, tarball_dir, output_dir) if options.export_dir: build_dir = export_dir else: build_dir = repo_dir if options.prebuild: RunAtCommand(options.prebuild, shell=True, extra_env={ 'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': build_dir })(dir=build_dir) setup_pbuilder(options) # Finally build the package: RunAtCommand(options.builder, dpkg_args, shell=True, extra_env={'GBP_BUILD_DIR': build_dir})(dir=build_dir) if options.postbuild: changes = os.path.abspath( "%s/../%s_%s_%s.changes" % (build_dir, source.sourcepkg, source.changelog.noepoch, changes_file_suffix(dpkg_args))) gbp.log.debug("Looking for changes file %s" % changes) Command(options.postbuild, shell=True, extra_env={ 'GBP_CHANGES_FILE': changes, 'GBP_BUILD_DIR': build_dir })() if options.tag or options.tag_only: gbp.log.info("Tagging %s" % source.changelog.version) tag = repo.version_to_tag(options.debian_tag, source.changelog.version) if options.retag and repo.has_tag(tag): repo.delete_tag(tag) repo.create_tag(name=tag, msg="%s Debian release %s" % (source.sourcepkg, source.changelog.version), sign=options.sign_tags, keyid=options.keyid) if options.posttag: sha = repo.rev_parse("%s^{}" % tag) Command(options.posttag, shell=True, extra_env={ 'GBP_TAG': tag, 'GBP_BRANCH': branch or '(no branch)', 'GBP_SHA1': sha })() except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 except DebianSourceError as err: gbp.log.err(err) source = None retval = 1 finally: drop_index() if not options.tag_only: if options.export_dir and options.purge and not retval: RemoveTree(export_dir)() if source and not gbp.notifications.notify(source.changelog, not retval, options.notify): gbp.log.err("Failed to send notification") retval = 1 return retval
def main(argv): dirs = dict(top=os.path.abspath(os.curdir)) needs_repo = False ret = 0 skipped = False options, args = parse_args(argv) if not options: return 1 try: if len(args) != 1: gbp.log.err( "Need to give exactly one package to import. Try --help.") raise GbpError else: try: repo = DebianGitRepository('.') is_empty = repo.is_empty() (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err( "Repository has uncommitted changes, commit these first: " ) raise GbpError(out) except GitRepositoryError: # no repo found, create one needs_repo = True is_empty = True pkg = args[0] if options.download: dsc = download_source(pkg, dirs=dirs, unauth=options.allow_unauthenticated) else: dsc = pkg src = DscFile.parse(dsc) if src.pkgformat not in ['1.0', '3.0']: raise GbpError( "Importing %s source format not yet supported." % src.pkgformat) if options.verbose: print_dsc(src) if needs_repo: if os.path.exists(src.pkg): raise GbpError( "Directory '%s' already exists. If you want to import into it, " "please change into this directory otherwise move it away first." % src.pkg) gbp.log.info("No git repository found, creating one.") repo = DebianGitRepository.create(src.pkg) os.chdir(repo.path) if repo.bare: disable_pristine_tar(options, "Bare repository") dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..')) upstream = DebianUpstreamSource(src.tgz) upstream.unpack(dirs['tmp'], options.filters) for tarball in src.additional_tarballs.values(): gbp.log.info("Found component tarball '%s'" % os.path.basename(tarball)) subtarball = DebianUpstreamSource(tarball) subtarball.unpack(upstream.unpacked, options.filters) format = [(options.upstream_tag, "Upstream"), (options.debian_tag, "Debian")][src.native] tag = repo.version_to_tag(format[0], src.upstream_version) msg = "%s version %s" % (format[1], src.upstream_version) if repo.find_version(options.debian_tag, src.version): gbp.log.warn("Version %s already imported." % src.version) if options.allow_same_version: gbp.log.info( "Moving tag of version '%s' since import forced" % src.version) move_tag_stamp(repo, options.debian_tag, src.version) else: raise SkipImport if not repo.find_version(format[0], src.upstream_version): gbp.log.info("Tag %s not found, importing %s tarball" % (tag, format[1])) if is_empty: branch = None else: branch = [options.upstream_branch, options.debian_branch][src.native] if not repo.has_branch(branch): if options.create_missing_branches: gbp.log.info("Creating missing branch '%s'" % branch) repo.create_branch(branch) else: gbp.log.err( no_upstream_branch_msg % branch + "\nAlso check the --create-missing-branches option." ) raise GbpError if src.native: author = get_author_from_changelog(upstream.unpacked) committer = get_committer_from_author(author, options) else: author = committer = {} commit = repo.commit_dir(upstream.unpacked, "Imported %s" % msg, branch, author=author, committer=committer) if not (src.native and options.skip_debian_tag): repo.create_tag(name=tag, msg=msg, commit=commit, sign=options.sign_tags, keyid=options.keyid) if not src.native: if is_empty: repo.create_branch(options.upstream_branch, commit) if options.pristine_tar: generate_pristine_tarballs(repo, src, options.upstream_branch) if (not repo.has_branch(options.debian_branch) and (is_empty or options.create_missing_branches)): repo.create_branch(options.debian_branch, commit) if not src.native: if src.diff or src.deb_tgz: apply_debian_patch(repo, upstream.unpacked, src, options, tag) else: gbp.log.warn("Didn't find a diff to apply.") if repo.get_branch() == options.debian_branch or is_empty: # Update HEAD if we modified the checked out branch repo.force_head(options.debian_branch, hard=True) except KeyboardInterrupt: ret = 1 gbp.log.err("Interrupted. Aborting.") except gbpc.CommandExecFailed: ret = 1 except GitRepositoryError as msg: gbp.log.err("Git command failed: %s" % msg) ret = 1 except GbpError as err: if str(err): gbp.log.err(err) ret = 1 except SkipImport: skipped = True finally: os.chdir(dirs['top']) for d in ['tmp', 'download']: if d in dirs: gbpc.RemoveTree(dirs[d])() if not ret and not skipped: gbp.log.info("Version '%s' imported under '%s'" % (src.version, src.pkg)) return ret
def main(argv): ret = 0 changelog = 'debian/changelog' until = 'HEAD' found_snapshot_banner = False version_change = {} branch = None options, args, dch_options, editor_cmd = parse_args(argv) if not options: return ExitCodes.parse_error try: old_cwd = os.path.abspath(os.path.curdir) try: repo = DebianGitRepository('.', toplevel=False) os.chdir(repo.path) except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) get_customizations(options.customization_file) try: branch = repo.get_branch() except GitRepositoryError: # Not being on any branch is o.k. with --ignore-branch if not options.ignore_branch: raise if options.debian_branch != branch and not options.ignore_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch)) raise GbpError( "Use --ignore-branch to ignore or --debian-branch to set the branch name." ) source = DebianSource('.') cp = maybe_create_changelog(repo, source, options) if options.since: since = options.since else: since = guess_documented_commit(cp, repo, options.debian_tag) if since: msg = "Continuing from commit '%s'" % since else: msg = "Starting from first commit" gbp.log.info(msg) found_snapshot_banner = has_snapshot_banner(cp) if args: gbp.log.info("Only looking for changes on '%s'" % " ".join(args)) commits = repo.get_commits(since=since, until=until, paths=args, options=options.git_log.split(" ")) commits.reverse() add_section = False # add a new changelog section if: if (options.new_version or options.bpo or options.nmu or options.qa or options.team or options.security or options.local_suffix): if options.bpo: version_change['increment'] = '--bpo' elif options.nmu: version_change['increment'] = '--nmu' elif options.qa: version_change['increment'] = '--qa' elif options.team: version_change['increment'] = '--team' elif options.security: version_change['increment'] = '--security' elif options.local_suffix: version_change[ 'increment'] = '--local=%s' % options.local_suffix else: version_change['version'] = options.new_version # the user wants to force a new version add_section = True elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner: if commits: # the last version was a release and we have pending commits add_section = True if options.snapshot: # the user want to switch to snapshot mode add_section = True if add_section and not version_change and not source.is_native(): # Get version from upstream if none provided v = guess_version_from_upstream(repo, options.upstream_tag, options.upstream_branch, cp) if v: version_change['version'] = v i = 0 for c in commits: i += 1 parsed = parse_commit(repo, c, options, last_commit=(i == len(commits))) commit_msg, (commit_author, commit_email) = parsed if not commit_msg: # Some commits can be ignored continue if add_section: # Add a section containing just this message (we can't # add an empty section with dch) cp.add_section(distribution="UNRELEASED", msg=commit_msg, version=version_change, author=commit_author, email=commit_email, dch_options=dch_options) # Adding a section only needs to happen once. add_section = False else: cp.add_entry(commit_msg, commit_author, commit_email, dch_options) # Show a message if there were no commits (not even ignored # commits). if not commits: gbp.log.info("No changes detected from %s to %s." % (since, until)) if add_section: # If we end up here, then there were no commits to include, # so we put a dummy message in the new section. cp.add_section(distribution="UNRELEASED", msg=["UNRELEASED"], version=version_change, dch_options=dch_options) fixup_section(repo, use_git_author=options.use_git_author, options=options, dch_options=dch_options) if options.release: do_release(changelog, repo, cp, use_git_author=options.use_git_author, dch_options=dch_options) elif options.snapshot: (snap, commit, version) = do_snapshot(changelog, repo, options.snapshot_number) gbp.log.info("Changelog %s (snapshot #%d) prepared up to %s" % (version, snap, commit[:7])) if editor_cmd: gbpc.Command(editor_cmd, ["debian/changelog"])() if options.postedit: cp = ChangeLog(filename=changelog) Hook('Postimport', options.postedit, extra_env={'GBP_DEBIAN_VERSION': cp.version})() if options.commit: # Get the version from the changelog file (since dch might # have incremented it, there's no way we can already know # the version). version = ChangeLog(filename=changelog).version # Commit the changes to the changelog file msg = changelog_commit_msg(options, version) repo.commit_files([changelog], msg) gbp.log.info("Changelog committed for version %s" % version) except KeyboardInterrupt: ret = 1 gbp.log.err("Interrupted. Aborting.") except (gbpc.CommandExecFailed, GbpError, GitRepositoryError, DebianSourceError, NoChangeLogError) as err: if str(err): gbp.log.err(err) ret = 1 maybe_debug_raise() finally: os.chdir(old_cwd) return ret
def main(argv): retval = 0 changelog = 'debian/changelog' cmd = [] try: options, args = parse_args(argv) except Exception as e: print("%s" % e, file=sys.stderr) return 1 gbp.log.setup(options.color, options.verbose, options.color_scheme) try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: branches = [] for branch in [ options.debian_branch, options.upstream_branch ]: if repo.has_branch(branch): branches += [ branch ] if repo.has_pristine_tar_branch() and options.pristine_tar: branches += [ repo.pristine_tar_branch ] try: cp = ChangeLog(filename=changelog) pkg = cp['Source'] except NoChangeLogError: pkg = None if not pkg: gbp.log.warn("Couldn't parse changelog, will use directory name.") pkg = os.path.basename(os.path.abspath(os.path.curdir)) pkg = os.path.splitext(pkg)[0] remote = parse_url(options.remote_url, options.name, pkg, options.template_dir) if repo.has_remote_repo(options.name): raise GbpError("You already have a remote name '%s' defined for this repository." % options.name) gbp.log.info("Shall I create a repository for '%(pkg)s' at '%(url)s' now? (y/n)?" % remote) if not read_yn(): raise GbpError("Aborted.") remote_script = build_remote_script(remote, branches[0]) if options.verbose: print(remote_script) cmd = build_cmd(remote) if options.verbose: print(cmd) proc = subprocess.Popen(cmd, stdin=subprocess.PIPE) proc.communicate(remote_script) if proc.returncode: raise GbpError("Error creating remote repository") push_branches(remote, branches) if options.track: setup_branch_tracking(repo, remote, branches) else: gbp.log.info("You can now add:") print_config(remote, branches) gbp.log.info("to your .git/config to 'gbp-pull' and 'git push' in the future.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 return retval
def main(argv): retval = 1 branch = None dest = None to_push = { 'refs': [], 'tags': [], } (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error if len(args) > 2: gbp.log.err("Only a single remote repository can be given") elif len(args) == 2: dest = args[1] gbp.log.setup(options.color, options.verbose, options.color_scheme) try: repo = DebianGitRepository(os.path.curdir, toplevel=False) except GitRepositoryError: gbp.log.err("%s is not inside a git repository" % (os.path.abspath('.'))) return 1 try: source = DebianSource(repo.path) branch = repo.branch if not options.ignore_branch: if branch != options.debian_branch: gbp.log.err("You are not on branch '%s' but %s" % (options.debian_branch, "on '%s'" % branch if branch else 'in detached HEAD state')) raise GbpError( "Use --ignore-branch to ignore or --debian-branch to set the branch name." ) if not dest: dest = get_remote(repo, branch) if options.debian_tag != '': dtag = repo.version_to_tag(options.debian_tag, source.version) if repo.has_tag(dtag): to_push['tags'].append(dtag) if source.is_releasable() and branch: ref = 'refs/heads/%s' % branch to_push['refs'].append((ref, get_push_src(repo, ref, dtag))) if not source.is_native(): if options.upstream_tag != '': utag = repo.version_to_tag(options.upstream_tag, source.upstream_version) if repo.has_tag(utag): to_push['tags'].append(utag) if options.upstream_branch != '': ref = 'refs/heads/%s' % options.upstream_branch to_push['refs'].append((ref, get_push_src(repo, ref, utag))) if options.pristine_tar: commit = repo.get_pristine_tar_commit(source) if commit: ref = 'refs/heads/pristine-tar' to_push['refs'].append( (ref, get_push_src(repo, ref, commit))) if do_push(repo, [dest], to_push, dry_run=options.dryrun): retval = 0 else: gbp.log.err("Failed to push some refs.") retval = 1 except (GbpError, GitRepositoryError, DebianSourceError) as err: if str(err): gbp.log.err(err) except KeyboardInterrupt: gbp.log.err("Interrupted. Aborting.") return retval
def main(argv): retval = 0 prefix = "git-" source = None hook_env = {} options, gbp_args, dpkg_args = parse_args(argv, prefix) if not options: return ExitCodes.parse_error try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: clean_working_tree(options, repo) check_branch(repo, options) tree = maybe_write_tree(repo, options) source = source_vfs(repo, options, tree) check_tag(options, repo, source) if not options.tag_only: output_dir = prepare_output_dir(options.export_dir) tarball_dir = options.tarball_dir or output_dir tmp_dir = os.path.join(output_dir, "%s-tmp" % source.sourcepkg) build_env, hook_env = setup_pbuilder(options, repo, source.is_native()) major = (source.debian_version if source.is_native() else source.upstream_version) export_dir = os.path.join(output_dir, "%s-%s" % (source.sourcepkg, major)) build_dir = export_dir if options.export_dir else repo.path changes_file = changes_file_name(source, build_dir, dpkg_args) # Get/build the upstream tarball if necessary. We delay this in # case of a postexport hook so the hook gets a chance to modify the # sources and create different tarballs (#640382) # We don't delay it in general since we want to fail early if the # tarball is missing. if not source.is_native(): if options.postexport: gbp.log.info( "Postexport hook set, delaying tarball creation") else: prepare_upstream_tarballs(repo, source, options, tarball_dir, output_dir) # Export to another build dir if requested: if options.export_dir: export_source(repo, tree, source, options, tmp_dir, tarball_dir) # Run postexport hook if options.postexport: Hook('Postexport', options.postexport, extra_env=Hook.md(hook_env, { 'GBP_GIT_DIR': repo.git_dir, 'GBP_TMP_DIR': tmp_dir }))(dir=tmp_dir) gbp.log.info("Moving '%s' to '%s'" % (tmp_dir, export_dir)) move_old_export(export_dir) os.rename(tmp_dir, export_dir) # Delayed tarball creation in case a postexport hook is used: if not source.is_native() and options.postexport: prepare_upstream_tarballs(repo, source, options, tarball_dir, output_dir) if options.prebuild: Hook('Prebuild', options.prebuild, extra_env=Hook.md(hook_env, { 'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': build_dir }))(dir=build_dir) # Finally build the package: RunAtCommand( options.builder, [pipes.quote(arg) for arg in dpkg_args], shell=True, extra_env=Hook.md(build_env, {'GBP_BUILD_DIR': build_dir}))(dir=build_dir) if options.postbuild: gbp.log.debug("Looking for changes file %s" % changes_file) Hook('Postbuild', options.postbuild, extra_env=Hook.md( hook_env, { 'GBP_CHANGES_FILE': changes_file, 'GBP_BUILD_DIR': build_dir }))() if options.tag or options.tag_only: perform_tagging(repo, source, options, hook_env) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 except DebianSourceError as err: gbp.log.err(err) source = None retval = 1 finally: drop_index(repo) if not options.tag_only: if options.export_dir and options.purge and not retval: RemoveTree(export_dir)() if source: summary, msg = gbp.notifications.build_msg(source.changelog, not retval) if not gbp.notifications.notify(summary, msg, options.notify): gbp.log.err("Failed to send notification") retval = 1 return retval