diff --git a/buildtools/build-release b/buildtools/build-release index 8a445964..db12cbeb 100755 --- a/buildtools/build-release +++ b/buildtools/build-release @@ -31,7 +31,11 @@ def build(git_repo, 'buildtools/'] # TODO: Capture output and write to log print(args) - rv = subprocess.run(args) + try: + returncode = subprocess.run(args).returncode + except OSError as exc: + print(f"{args[0]}: {exc}",file=sys.stderr) + returncode = 127 report_filepath = os.path.join(pkgdirpath,"build-report.txt") with open(report_filepath,"a+") as f: build = os.path.basename(containerfile) @@ -39,12 +43,14 @@ def build(git_repo, f.write(f"branch={branch}; ") f.write(f"timestamp={timestamp}; ") f.write("rv=") - if rv.returncode == 0: + if returncode == 0: f.write("success;") else: f.write("fail;") f.write("\n") + return returncode + def setup(): # Detect distribution @@ -98,7 +104,10 @@ def podman_cleanup(): 'prune', '-af'] print(args) - subprocess.run(args) + try: + subprocess.run(args) + except OSError as exc: + print(f"{args[0]}: {exc}",file=sys.stderr) def parse_args(): @@ -108,7 +117,7 @@ def parse_args(): p.add_argument('--pkgdirpath', default='build/pkgs/') p.add_argument('--branch', - default='master') + required=False) p.add_argument('--setup', required=False, action='store_true') @@ -136,6 +145,10 @@ def main(): setup() sys.exit(0) + if not args.branch: + print("error: the following arguments are required: --branch") + sys.exit(1) + if not args.git_repo: print("error: the following arguments are required: --git-repo") sys.exit(1) @@ -163,15 +176,21 @@ def main(): containerfile = f'buildtools/containerfiles/{filename}' containerfiles.append(containerfile) + if not containerfiles: + sys.exit(f"no package targets match {args.target!r}") + + failed = False for containerfile in containerfiles: if args.cleanup: podman_cleanup() - build(git_repo=args.git_repo, - branch=args.branch, - containerfile=containerfile, - pkgdirpath=args.pkgdirpath) + rv = build(git_repo=args.git_repo, + branch=args.branch, + containerfile=containerfile, + pkgdirpath=args.pkgdirpath) + if rv != 0: + failed = True - sys.exit(0) + sys.exit(1 if failed else 0) if __name__ == '__main__': diff --git a/buildtools/containerfiles/static.installer b/buildtools/containerfiles/static.installer deleted file mode 100644 index 0d3b29b8..00000000 --- a/buildtools/containerfiles/static.installer +++ /dev/null @@ -1,14 +0,0 @@ -ARG BUILD_TIMESTAMP=0 -FROM --platform=linux/amd64 ubuntu:latest as build -COPY install-build-pkgs /tmp/ -RUN /tmp/install-build-pkgs && \ - DEBIAN_FRONTEND=noninteractive apt-get -qy --no-install-suggests --no-install-recommends install \ - makeself -RUN mkdir -p /tmp/mergerfs/ -RUN ls -lhd /pkgs -RUN cp -v /pkgs/*static*.gz /tmp/mergerfs/ -RUN mkdir -p /build -RUN makeself /tmp/mergerfs/ /build/mergerfs-installer.run "mergerfs" echo "foo" - -FROM scratch -COPY --from=build /build/ / diff --git a/buildtools/containerfiles/tarball b/buildtools/containerfiles/tarball index 182c8478..8f3585dd 100644 --- a/buildtools/containerfiles/tarball +++ b/buildtools/containerfiles/tarball @@ -4,7 +4,7 @@ COPY install-build-pkgs /tmp/ RUN /tmp/install-build-pkgs ARG BUILD_TIMESTAMP=0 -ARG BRANCH=master +ARG BRANCH ARG GIT_REPO RUN git clone --single-branch "${GIT_REPO}" /tmp/mergerfs --branch="${BRANCH}" diff --git a/buildtools/git2debcl b/buildtools/git2debcl index 64ff2083..6ef507e0 100755 --- a/buildtools/git2debcl +++ b/buildtools/git2debcl @@ -30,7 +30,9 @@ Generated debian/changelog from git log Options: --name NAME Name of package (required) - --version VERSION Place in git history to include upto (default: ::guess::) + --version VERSION Package version (default: infer from Git). If it names + a tag, end the changelog there; otherwise use HEAD. + Required in shallow clones with no reachable tag. --distro DISTRO Distribution name (default: ::guess::) --codename NAME Distribution codename (default: ::guess::) --urgency URGENCY Urgency (default: medium) @@ -78,16 +80,28 @@ if [ -z "$NAME" ]; then usage fi -# Function to get git tags sorted in reverse order +# Function to get reachable release tags sorted in reverse version order. +# A final release sorts after its release candidates. git_tags() { - git tag -l | sort -rV + local version_ref="$1" + git -c versionsort.suffix=-rc tag \ + --merged "$version_ref" --sort=-version:refname --list | + grep -E '^[0-9]+([.][0-9]+)*(-rc[0-9]+)?$' } -# Function to get git log between two tags +# Function to get git log reachable from totag but not fromtag git_log() { local fromtag="$1" local totag="$2" - git log --no-merges --oneline "${fromtag}...${totag}" 2>/dev/null + git log --no-merges --oneline "${fromtag}..${totag}" 2>/dev/null +} + +# dpkg splits a version at the last '-' and sorts '-' above '~', so +# printing an rc tag as 2.42.0-rc1~dist would compare above the final +# 2.42.0~dist release. Emit rc tags with a doubled '~' instead; tag +# lookups, ranges, and ordering keep the raw names. +deb_version() { + printf '%s\n' "$1" | sed 's/-rc/~~rc/' } # Function to get author and time for a tag @@ -98,7 +112,29 @@ git_author_and_time() { # Function to get git version git_version() { - git describe --always --tags --dirty 2>/dev/null || echo "unknown" + # Empty match prevents describe from considering tags when none are + # eligible. Every other match is an exact reachable release tag. + set -- --match '' + while IFS= read -r tag; do + if [ -n "$tag" ]; then + set -- "$@" --match "$tag" + fi + done </dev/null || { + commit=$(git rev-parse --short HEAD) || return 1 + if [ "$(git rev-parse --is-shallow-repository)" != false ]; then + echo "Error: tagless snapshots need full history; fetch it or specify --version" >&2 + return 1 + fi + count=$(git rev-list --count HEAD) || return 1 + if ! git diff --quiet 2>/dev/null || + ! git diff --cached --quiet 2>/dev/null; then + commit="${commit}-dirty" + fi + printf '0~git.%s.%s\n' "$count" "$commit" + } } # Function to guess distribution @@ -129,28 +165,50 @@ if [ "$CODENAME" = "::guess::" ]; then fi if [ "$VERSION" = "::guess::" ]; then - VERSION=$(git_version) + VERSION=$(git_version) || exit 1 fi # Version suffix VERSUFFIX="~${DISTRO}-${CODENAME}" -# Get all tags -TAGS=$(git_tags) +# If version names a tag, end the changelog there; otherwise use HEAD. +if git rev-parse --verify "refs/tags/${VERSION}^{commit}" >/dev/null 2>&1; then + VERSION_REF="$VERSION" +else + VERSION_REF=HEAD +fi -# Create temporary file for tag pairs +# A requested tag may have history even when HEAD is unborn. +git rev-parse --verify "${VERSION_REF}^{commit}" >/dev/null || exit 1 + +# Only release tags reachable from the requested ref are eligible. +TAGS=$(git_tags "$VERSION_REF") + +# Create temporary file for tag pairs. The first line also covers an explicit +# version on an untagged HEAD and a requested non-release tag. TMPFILE=$(mktemp) trap 'rm -f "$TMPFILE"' EXIT +{ + printf '%s %s\n' "$VERSION" "$VERSION_REF" + printf '%s\n' "$TAGS" +} > "$TMPFILE" -# Check if version is in tags -if echo "$TAGS" | grep -q "^${VERSION}$"; then - # If version is a tag, start from that tag - echo "$TAGS" | awk -v ver="$VERSION" 'BEGIN{found=0} {if($0==ver)found=1; if(found)print}' > "$TMPFILE" -else - # If version is not a tag, use HEAD as starting point - echo "$VERSION HEAD" > "$TMPFILE" - echo "$TAGS" >> "$TMPFILE" -fi +# Print one changelog entry: header, log lines, then author and time +print_entry() { + local tag="$1" + local ref="$2" + local entries="$3" + + printf "%s (%s%s) %s; urgency=%s\n\n" "$NAME" "$(deb_version "$tag")" "$VERSUFFIX" "$CODENAME" "$URGENCY" + + echo "$entries" | while IFS= read -r entry; do + if [ -n "$entry" ]; then + printf " * %s\n" "$entry" + fi + done + + printf "\n %s\n\n" "$(git_author_and_time "$ref")" +} # Process tags and generate changelog PREV_TAG="" @@ -162,41 +220,41 @@ while IFS= read -r line; do continue fi - # Handle the special case of VERSION HEAD - if [ "$line" = "$VERSION HEAD" ]; then + # Handle the requested version and ref on the first line + if [ "$line" = "$VERSION $VERSION_REF" ]; then TAG="$VERSION" - REF="HEAD" + REF="$VERSION_REF" else TAG="$line" REF="$line" fi if [ -n "$PREV_TAG" ]; then - # Get log entries between current and previous tag - LOG_ENTRIES=$(git_log "$REF" "$PREV_REF") - - # Skip if no changes - if [ -z "$LOG_ENTRIES" ] || [ "$LOG_ENTRIES" = "" ]; then - PREV_TAG="$TAG" - PREV_REF="$REF" + # Version order does not make sibling tags comparable. Skip this + # boundary and keep the newer tag for an actual ancestor. + if ! git merge-base --is-ancestor "$REF" "$PREV_REF"; then continue fi - # Print package header - printf "%s (%s%s) %s; urgency=%s\n\n" "$NAME" "$PREV_TAG" "$VERSUFFIX" "$CODENAME" "$URGENCY" + # Get log entries between current and previous tag + LOG_ENTRIES=$(git_log "$REF" "$PREV_REF") - # Print each log entry - echo "$LOG_ENTRIES" | while IFS= read -r entry; do - if [ -n "$entry" ]; then - printf " * %s\n" "$entry" - fi - done + # Tags at the same revision have no changes between them. Keep the + # newer version for the next nonempty range. + if [ -z "$LOG_ENTRIES" ]; then + continue + fi - # Print author and time - AUTHOR_TIME=$(git_author_and_time "$PREV_REF") - printf "\n %s\n\n" "$AUTHOR_TIME" + print_entry "$PREV_TAG" "$PREV_REF" "$LOG_ENTRIES" + FIRST=0 fi PREV_TAG="$TAG" PREV_REF="$REF" done < "$TMPFILE" + +# If no tag range produced an entry, list the requested version's history. +if [ "$FIRST" = 1 ]; then + LOG_ENTRIES=$(git log --no-merges --oneline "$VERSION_REF" --) || exit 1 + print_entry "$VERSION" "$VERSION_REF" "$LOG_ENTRIES" +fi diff --git a/mkdocs/docs/setup/build.md b/mkdocs/docs/setup/build.md index 674716f3..b4a36d54 100644 --- a/mkdocs/docs/setup/build.md +++ b/mkdocs/docs/setup/build.md @@ -72,6 +72,22 @@ Fedora 45 on `amd64` and `arm64`, and Ubuntu 26.10 on `amd64`, `arm64`, `armhf`, and `riscv64`. Foreign-architecture builds require QEMU/binfmt support. +Standalone static archives (`mergerfs--static-linux_.tar.gz`) +are built with `make release-static`, which selects every `static.` +containerfile: `amd64`, `arm64`, `armhf`, `i386`, and `riscv64`. +`make release-all` builds every containerfile in the directory. A target +name that matches no containerfile (exact or substring) makes +`buildtools/build-release` fail with `no package targets match ''`; +there is no installer target. + +For a release, pass the intended tag to the Makefile (`GITREF=`) +or call `buildtools/build-release` directly with both `--git-repo` (the +repository for the container to clone) and `--branch` (the intended +tag); the script fails when either is missing. The named ref must be +available in that repository. A failed target gives the driver a +nonzero exit status; `build-report.txt` in the output directory lists +each target's result. + ## Generic Linux Have git, g++ or clang, make, python installed. diff --git a/tests/TEST_release_metadata b/tests/TEST_release_metadata index 35c5c72f..2c1dc045 100755 --- a/tests/TEST_release_metadata +++ b/tests/TEST_release_metadata @@ -3,6 +3,8 @@ import json import os from pathlib import Path +import re +import shutil import subprocess import sys import tempfile @@ -11,6 +13,71 @@ import unittest ROOT = Path(__file__).resolve().parents[1] BUILD_RELEASE = ROOT / "buildtools" / "build-release" +GIT2DEBCL = ROOT / "buildtools" / "git2debcl" + + +def _deb_order_char(char): + # dpkg verrevcmp's order(): digits group first, '~' sorts before + # everything else, letters sort by value, other punctuation last. + if char.isdigit(): + return 0 + if char.isalpha(): + return ord(char) + if char == "~": + return -1 + if char: + return ord(char) + 256 + return 0 + + +def _deb_verrevcmp(a, b): + i = j = 0 + while i < len(a) or j < len(b): + first_diff = 0 + while ((i < len(a) and not a[i].isdigit()) or + (j < len(b) and not b[j].isdigit())): + ac = _deb_order_char(a[i]) if i < len(a) else 0 + bc = _deb_order_char(b[j]) if j < len(b) else 0 + if ac != bc: + return -1 if ac < bc else 1 + i += 1 + j += 1 + while i < len(a) and a[i] == "0": + i += 1 + while j < len(b) and b[j] == "0": + j += 1 + while i < len(a) and a[i].isdigit() and j < len(b) and b[j].isdigit(): + if first_diff == 0: + first_diff = ord(a[i]) - ord(b[j]) + i += 1 + j += 1 + if i < len(a) and a[i].isdigit(): + return 1 + if j < len(b) and b[j].isdigit(): + return -1 + if first_diff: + return -1 if first_diff < 0 else 1 + return 0 + + +def deb_vercmp(a, b): + # Compact port of dpkg's version comparison: epoch, then upstream + # version, then Debian revision, each compared with verrevcmp. + def split(value): + epoch, sep, rest = value.partition(":") + if not sep: + epoch, rest = "0", value + upstream, _, revision = rest.rpartition("-") + return int(epoch), upstream, revision + + epoch_a, upstream_a, revision_a = split(a) + epoch_b, upstream_b, revision_b = split(b) + if epoch_a != epoch_b: + return -1 if epoch_a < epoch_b else 1 + rv = _deb_verrevcmp(upstream_a, upstream_b) + if rv: + return rv + return _deb_verrevcmp(revision_a, revision_b) class ReleaseMetadataTests(unittest.TestCase): @@ -23,6 +90,7 @@ class ReleaseMetadataTests(unittest.TestCase): self.root = Path(tmp.name) self.home = self.root / "home" self.home.mkdir() + self.repo = None def base_env(self): env = os.environ.copy() @@ -51,11 +119,90 @@ class ReleaseMetadataTests(unittest.TestCase): stderr=subprocess.PIPE, text=True, timeout=timeout, ) - def run_driver(self, fail_target="", missing_podman=False, branch="test"): + def make_repo(self, name="repo"): + self.repo = self.root / name + rv = self.run_command(["git", "init", "-q", self.repo], self.root) + self.assertEqual(rv.returncode, 0, msg=rv.stderr) + + def git(self, *args, check=True, date=None): + env = self.base_env() + if date is not None: + value = "{} +0000".format(date) + env["GIT_AUTHOR_DATE"] = value + env["GIT_COMMITTER_DATE"] = value + rv = self.run_command(["git", "-C", self.repo, *args], self.repo, env) + if check and rv.returncode != 0: + self.fail("git {} failed\nstdout:\n{}\nstderr:\n{}".format( + " ".join(args), rv.stdout, rv.stderr)) + return rv + + def commit(self, subject, sequence): + self.git( + "commit", + "--allow-empty", + "--no-gpg-sign", + "-q", + "-m", + subject, + date=1700000000 + sequence * 60, + ) + return self.git("rev-parse", "HEAD").stdout.strip() + + def tag(self, name, ref="HEAD"): + self.git("tag", name, ref) + + def commit_tag(self, subject, sequence, name): + ref = self.commit(subject, sequence) + self.tag(name, ref) + return ref + + def changelog(self, version=None, expected=0): + args = [ + GIT2DEBCL, + "--name", + "mergerfs", + "--distro", + "debian", + "--codename", + "test", + ] + if version is not None: + args.extend(["--version", version]) + rv = self.run_command(args, cwd=self.repo) + message = "stdout:\n{}\nstderr:\n{}".format(rv.stdout, rv.stderr) + self.assertEqual(rv.returncode, expected, msg=message) + return rv + + def changelog_versions(self, output): + return re.findall( + r"(?m)^mergerfs \((.*?)~debian-test\) test; urgency=medium$", output) + + def deb_order(self, a, b): + dpkg = shutil.which("dpkg") + if dpkg is not None: + for op, rv in (("lt", -1), ("eq", 0)): + proc = self.run_command( + [dpkg, "--compare-versions", a, op, b], self.root) + if proc.returncode == 0: + return rv + return 1 + return deb_vercmp(a, b) + + def assert_deb_less(self, a, b): + self.assertLess( + self.deb_order(a, b), 0, "expected {} < {}".format(a, b)) + + def assert_commit_listed(self, output, subject): + pattern = r"(?m)^ \* [0-9a-f]+ {}$".format(re.escape(subject)) + self.assertRegex(output, pattern) + + def run_driver(self, fail_target="", missing_podman=False, branch="test", + target="all", fixtures=("debian-bad", "debian-good"), + cwd=None): work = self.root / "driver" containers = work / "buildtools" / "containerfiles" containers.mkdir(parents=True) - for name in ("debian-bad", "debian-good"): + for name in fixtures: (containers / name).write_text("# test fixture\n", encoding="ascii") repo = work / "repo" @@ -92,13 +239,14 @@ raise SystemExit(0) driver_args = [ sys.executable, BUILD_RELEASE, - "--target=all", + "--target={}".format(target), "--git-repo={}".format(repo), "--pkgdirpath={}".format(packages), ] if branch is not None: driver_args.append("--branch={}".format(branch)) - rv = self.run_command(driver_args, cwd=work, env=env) + rv = self.run_command( + driver_args, cwd=work if cwd is None else cwd, env=env) calls = [] if podman_log.exists(): calls = [ @@ -134,6 +282,259 @@ raise SystemExit(0) self.assert_driver_report(report, "success") self.assert_local_volume_syntax(calls) + def test_driver_rejects_missing_branch(self): + rv, calls, report = self.run_driver(branch=None) + self.assertNotEqual(rv.returncode, 0, msg=rv.stdout + rv.stderr) + self.assertIn("--branch", rv.stdout + rv.stderr) + self.assertEqual(calls, []) + self.assertEqual(report, []) + + def test_driver_one_bad_among_good(self): + rv, calls, report = self.run_driver(fail_target="debian-bad") + self.assertNotEqual(rv.returncode, 0, msg=rv.stdout + rv.stderr) + self.assertEqual(len(calls), 2) + self.assert_driver_report(report, "fail") + self.assert_local_volume_syntax(calls) + + def test_driver_missing_podman_reports_every_target(self): + rv, calls, report = self.run_driver(missing_podman=True) + self.assertNotEqual(rv.returncode, 0, msg=rv.stdout + rv.stderr) + self.assertEqual(calls, []) + self.assertEqual(len(report), 2) + for line, name in zip(report, ("debian-bad", "debian-good")): + self.assertRegex( + line, + r"^{}: branch=test; timestamp=\d+; rv=fail;$".format(name), + ) + + def test_driver_static_target_builds_all_static_archives(self): + # Exercises the real buildtools/containerfiles directory so the + # post-withdrawal selection is locked, not just the matching logic. + static_archives = ( + "static.amd64", + "static.arm64", + "static.armhf", + "static.i386", + "static.riscv64", + ) + rv, calls, report = self.run_driver(target="static", cwd=ROOT) + self.assertEqual(rv.returncode, 0, msg=rv.stdout + rv.stderr) + built = [ + os.path.basename(call[call.index("-f") + 1]) for call in calls + ] + self.assertEqual(built, list(static_archives)) + self.assertEqual(len(report), len(static_archives)) + for line, name in zip(report, static_archives): + self.assertRegex( + line, + r"^{}: branch=test; timestamp=\d+; rv=success;$".format(name), + ) + + def test_driver_unmatched_target_fails_without_building(self): + rv, calls, report = self.run_driver(target="installer", cwd=ROOT) + self.assertNotEqual(rv.returncode, 0, msg=rv.stdout + rv.stderr) + self.assertIn("no package targets match 'installer'", rv.stderr) + self.assertEqual(calls, []) + self.assertEqual(report, []) + + def test_changelog_excludes_foreign_and_nonrelease_tags(self): + self.make_repo() + base = self.commit_tag("base", 1, "1.0") + first = self.commit_tag("main one", 2, "1.1") + + self.git("checkout", "-q", "-b", "side", base) + side = self.commit("side private", 3) + self.tag("9.0", side) + self.git("checkout", "-q", "-") + + second = self.commit_tag("main two", 4, "1.2") + head = self.commit("head work", 5) + self.tag("backup-pre-docsplit", head) + self.tag("2backup", head) + self.git( + "tag", "-a", "snapshot-note", "-m", "snapshot", head, + date=1700000900, + ) + + output = self.changelog("2.0").stdout + self.assertEqual( + self.changelog_versions(output), ["2.0", "1.2", "1.1"] + ) + for subject in ("head work", "main two", "main one"): + self.assert_commit_listed(output, subject) + self.assertNotIn("side private", output) + self.assertNotIn("backup-pre-docsplit", output) + self.assertNotIn("2backup", output) + self.assertNotIn("snapshot-note", output) + self.assertNotIn("(9.0~debian-test)", output) + + guessed = self.changelog().stdout + versions = self.changelog_versions(guessed) + self.assertTrue(versions) + self.assertRegex(versions[0], r"^1\.2-1-g[0-9a-f]+$") + for name in ("backup-pre-docsplit", "2backup", "snapshot-note"): + self.assertNotIn(name, guessed) + self.assert_commit_listed(guessed, "head work") + + def test_prerelease_order_and_requested_ref_bound(self): + self.make_repo() + base = self.commit_tag("base", 1, "2.41.1") + rc0 = self.commit_tag("rc zero", 2, "2.42.0-rc0") + rc1 = self.commit_tag("rc one", 3, "2.42.0-rc1") + rc2 = self.commit_tag("rc two", 4, "2.42.0-rc2") + rc3 = self.commit_tag("rc three", 5, "2.42.0-rc3") + final = self.commit_tag("final release", 6, "2.42.0") + self.commit("head work", 7) + + output = self.changelog("2.42.1").stdout + self.assertEqual( + self.changelog_versions(output), + [ + "2.42.1", + "2.42.0", + "2.42.0~~rc3", + "2.42.0~~rc2", + "2.42.0~~rc1", + "2.42.0~~rc0", + ], + ) + for subject in ( + "head work", + "final release", + "rc three", + "rc two", + "rc one", + "rc zero", + ): + self.assert_commit_listed(output, subject) + + output = self.changelog("2.42.0-rc2").stdout + self.assertEqual( + self.changelog_versions(output), + ["2.42.0~~rc2", "2.42.0~~rc1", "2.42.0~~rc0"], + ) + for subject in ("rc two", "rc one", "rc zero"): + self.assert_commit_listed(output, subject) + self.assertNotIn("rc three", output) + self.assertNotIn("final release", output) + self.assertNotIn("head work", output) + + def test_rc_package_version_sorts_below_final_release(self): + self.make_repo() + self.commit_tag("previous release", 0, "2.41.0") + self.commit_tag("rc one", 1, "2.42.0-rc1") + self.commit_tag("rc two", 2, "2.42.0-rc2") + self.commit_tag("final release", 3, "2.42.0") + + output = self.changelog("2.42.0").stdout + self.assertIn( + "mergerfs (2.42.0~~rc1~debian-test) test; urgency=medium", + output, + ) + self.assertNotIn("(2.42.0-rc1~debian-test)", output) + self.assertNotIn("(2.42.0-rc2~debian-test)", output) + + # dpkg splits a package version at the last '-' and sorts '-' + # above '~', so the printed rc tags must double the '~' to sort + # below the final release while staying above the previous one. + rc1 = "2.42.0~~rc1~debian-test" + rc2 = "2.42.0~~rc2~debian-test" + final = "2.42.0~debian-test" + self.assert_deb_less("2.41.0~debian-test", rc1) + self.assert_deb_less(rc1, rc2) + self.assert_deb_less(rc2, final) + + self.commit("head work", 4) + snapshot = self.changelog_versions(self.changelog().stdout)[0] + self.assertRegex(snapshot, r"^2\.42\.0-1-g[0-9a-f]+$") + self.assert_deb_less(final, "{}~debian-test".format(snapshot)) + + def test_incomparable_release_tags_skip_boundary(self): + self.make_repo() + base = self.commit_tag("base", 1, "1.0") + self.git("checkout", "-q", "-b", "side", base) + self.commit_tag("side release", 2, "1.1") + self.git("checkout", "-q", "-") + self.commit_tag("main release", 3, "2.0") + self.git( + "merge", "-q", "--no-ff", "--no-gpg-sign", "-m", "merge side", + "side", date=1700000900, + ) + + output = self.changelog("3.0").stdout + self.assertEqual(self.changelog_versions(output), ["3.0", "2.0"]) + self.assertEqual(output.count("side release"), 1) + self.assert_commit_listed(output, "main release") + + def test_same_commit_tags_keep_newer_nonempty_history(self): + self.make_repo() + base = self.commit_tag("base", 1, "1.0") + middle = self.commit("middle", 2) + self.tag("1.1", middle) + self.tag("1.2", middle) + self.commit("head work", 3) + + output = self.changelog("2.0").stdout + self.assertEqual(self.changelog_versions(output), ["2.0", "1.2"]) + self.assert_commit_listed(output, "head work") + self.assert_commit_listed(output, "middle") + + output = self.changelog("1.0").stdout + self.assertEqual(self.changelog_versions(output), ["1.0"]) + self.assert_commit_listed(output, "base") + + def test_tagless_snapshot_and_explicit_version(self): + self.make_repo() + self.commit("tagless base", 1) + self.commit("tagless head", 2) + describe = self.git("rev-parse", "--short", "HEAD").stdout.strip() + + output = self.changelog().stdout + self.assertEqual( + self.changelog_versions(output), + ["0~git.2.{}".format(describe)], + ) + self.assert_commit_listed(output, "tagless base") + self.assert_commit_listed(output, "tagless head") + + output = self.changelog("2.42.4").stdout + self.assertEqual(self.changelog_versions(output), ["2.42.4"]) + self.assert_commit_listed(output, "tagless base") + self.assert_commit_listed(output, "tagless head") + + self.tag("2backup") + self.git( + "tag", "-a", "snapshot-note", "-m", "snapshot", "HEAD", + date=1700000900, + ) + output = self.changelog().stdout + self.assertEqual( + self.changelog_versions(output), + ["0~git.2.{}".format(describe)], + ) + self.assertNotIn("2backup", output) + self.assertNotIn("snapshot-note", output) + + def test_shallow_tagless_requires_explicit_version(self): + self.make_repo("source") + self.commit("base", 1) + self.commit("shallow head", 2) + source = self.repo + shallow = self.root / "shallow" + rv = self.run_command( + ["git", "clone", "-q", "--no-local", "--depth", "1", "--no-tags", + "file://{}".format(source), shallow], + self.root, + ) + self.assertEqual(rv.returncode, 0, msg=rv.stderr) + self.repo = shallow + + failed = self.changelog(expected=1) + self.assertIn("tagless snapshots need full history", failed.stderr) + output = self.changelog("2.0").stdout + self.assertEqual(self.changelog_versions(output), ["2.0"]) + self.assert_commit_listed(output, "shallow head") + if __name__ == "__main__": unittest.main()