Skip to content

Conversation

@darukutsu
Copy link
Contributor

@darukutsu darukutsu commented Nov 21, 2025

Checklist

  • Admin:
    • No duplicate PRs
  • Integration:
    • Always add unit tests for fixes or new functionality
    • If adding new options, update dist/completion/*
  • Documentation:
    • If adding new options, update usage and doc/*.ronn
    • If adding new strings, update locale/*.po

Description

If you don't store all tarballs in your ~/.cache/yay (like me, store only last 2) or if you use other aur-manager you could instead use vcs to switch to desired branch and rebuild chosen version. Hopefully everything works as should, tested only for yay.

@darukutsu
Copy link
Contributor Author

darukutsu commented Nov 22, 2025

Added some tests, however i don't understand yet how syntax works, so will edit them when I figure out.

Copy link
Member

@pbrisbin pbrisbin left a comment

Choose a reason for hiding this comment

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

This is looking good. Sorry, I should've warned you not to worry about the existing shfmt / shellcheck stuff.

@darukutsu
Copy link
Contributor Author

darukutsu commented Dec 30, 2025

I realized that makepkg -fs outputs correct pkg name so no more need to rename and rename back to use gitpkg... now its literally placeholder for build_pkg() to determine whether it should be build. File with gitpkg never exists. So only what we need to alter is to_install array and I come up with safe solution. That previous renaming using -ctime wasn't imo very good solution.

see

593: printf "%s\0" "$item" >> new_to_install.downgrade

613: mapfile -d '' to_install < new_to_install.downgrade
614: rm new_to_install.downgrade

Here's simple command how to try build something from aur

 $ downgrade --git --pacman-cache ~/.cache/yay --maxdepth 2 'ani-cli>4.7' bash

Copy link
Member

@pbrisbin pbrisbin left a comment

Choose a reason for hiding this comment

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

Left some thoughts, but nothing blocking. Let me know if you'd like to address them before merging.

@pbrisbin
Copy link
Member

pbrisbin commented Jan 5, 2026

I'm going to push a commit that improves the "No fixture found" error message, and then does the thing it suggests to fix those. The remaining failures seem like they may just be actual bugs.

@pbrisbin
Copy link
Member

pbrisbin commented Jan 5, 2026

Looking at the test failures, I see a few examples like:

   > search_ala 'xorg-twm' | filter_packages 'xorg-twm' '=' '1.0.8-1'
   https://archive.archlinux.org/packages/x/xorg-twm/xorg-twm-1.0.8-1-x86_64.pkg.tar.xz
+  https://archive.archlinux.org/packages/x/xorg-twm/xorg-twm-1.0.8-2-x86_64.pkg.tar.xz
+  https://archive.archlinux.org/packages/x/xorg-twm/xorg-twm-1.0.8-3-x86_64.pkg.tar.xz

This test is really about = and ensuring that the results are exactly and only 1.0.8-1. The + lines indicate this has been broken since the 1.0.8-2 and -3 lines are being returned unexpectedly.

Is it possible your regex changes are causing the operators filtering to no longer work?

@darukutsu
Copy link
Contributor Author

I fixed regex already, however I don't understand why search_git is not outputting anything. It should, since we clone repo and set correct path to CacheDir. Once I figured that out I push fixes.

@darukutsu
Copy link
Contributor Author

I'm idiot I forgot to read config values now it should be without error.

@darukutsu
Copy link
Contributor Author

hopefully i rebased correctly, first time doing this :D

@darukutsu
Copy link
Contributor Author

dont run workflows yet, I just discovered just test from your readme will fix issue then after next commit

@darukutsu
Copy link
Contributor Author

So this part should match multiple lines so when you update we don't have to rewrite test to add new version however it matches only first match. So i assume cram does not support multiline regex match. Any suggestion?

  $ search_git 'downgrade' | filter_packages 'downgrade' '>' '6.0.0'
  /tmp/.*/downgrade-(?!6\.0\.0)[0-9.]+-.*-any.gitpkg.tar.gz (re)
  /tmp/.*/downgrade-([6-9]|[1-9][0-9]+).[0-9.-]+-.*-any.gitpkg.tar.gz (re)

@darukutsu
Copy link
Contributor Author

darukutsu commented Jan 8, 2026

Ok so come up with workaround to use grep -vP and if there something that isn't matched it will spew out as unmatched line. Or if don't like this solution maybe switch to bats as suggested in #170 but I have no idea if they have multiline support. There is still issue with su needs authentication. Maybe fake su binary that does nothing. It depends whether container is root by default or not. If it is, we have switch user so we can actually use makepkg otherwise just hide su binary.

@pbrisbin
Copy link
Member

pbrisbin commented Jan 8, 2026

So i assume cram does not support multiline regex match. Any suggestion?

That's correct. Cram is basically golden testing, so it should be written to match all the expected output. The glob and regex form can be useful, but should be used sparingly.

I would probably use tail (or head depending on how it sorts) to filter to the oldest 3 (or so) tags, then you can just match exactly because that output should remain stable even when new tags are added.

  $ search_git 'downgrade' | tail -n 3
  /tmp/*/downgrade-3.2-1-any.gitpkg.tar.gz (glob)
  /tmp/*/downgrade-3.1-1-any.gitpkg.tar.gz (glob)
  /tmp/*/downgrade-2.1-1-any.gitpkg.tar.gz (glob)

Does that work?

There is still issue with su needs authentication. Maybe fake su binary that does nothing

I'm personally OK if we just don't test that function, it seems hard to get any useful test coverage there. It's an add-on / special case thing that, if it breaks, downgrade can still be used generally.

@darukutsu
Copy link
Contributor Author

darukutsu commented Jan 8, 2026

did i mess up something?

@darukutsu
Copy link
Contributor Author

just test passing on my side don't understand why did this happen

@pbrisbin
Copy link
Member

pbrisbin commented Jan 8, 2026

OK, I see what's happening. If you are happy with it now, I can take it from here and push some fixes before merging.

pbrisbin and others added 2 commits January 8, 2026 10:51
On GHA, tests that run in containers must use `root`[^1]. Otherwise, you
don't have access to write in the workspace. For example, our tests
failing couldn't write the `.t.err` files.

Therefore, to use the `archlinux` container, we have to remove this test
that was asserting errors when running as non-`root`.

In testing that this would work, I used `sudo just test` locally, which
ran into an unrelated error being unable to write in `/tmp`. This is
probably solvable, but we never used that file, so I replaced it with
`/dev/null`.

Lastly, I installed `git` since I know we'll need that.

[^1]: https://docs.github.com/en/actions/reference/workflows-and-actions/dockerfile-support#user
This is fully opt-in by the `--git` option (or equivalent env var).

If enabled, we check to see if the configured cache directory represents
the git repository. This would be the case if the user is downgrading an
AUR package installed via `yay`. In such a repository, we can hunt for
commits that represent the older versions of the package and present
them as options to downgrade to. If selected, we can check out that
commit and build the package at that version (if necessary) and install
it.

The logic is isolated to a `search_git` function, for handling locating
commits that represent versions and output potential package names that
include "gitpkg" in them, and a `build_pkg` function that looks for such
package names and builds them. We have to be careful to use `su` so that
`makepkg` is not run as root. The only changes to `downgrade` outside of
these new functions is to regexs used to locate and parse package names,
but this is well covered by tests.
@pbrisbin
Copy link
Member

pbrisbin commented Jan 8, 2026

OK, I'm done and ready to merge. I will let this sit for a few hours in case you want to review my changes, commit messages, etc.

Thanks for the contribution, I hope it works well for you!

@darukutsu
Copy link
Contributor Author

lgtm

@pbrisbin pbrisbin merged commit 3fd2cdc into archlinux-downgrade:main Jan 8, 2026
3 checks passed
@darukutsu
Copy link
Contributor Author

darukutsu commented Jan 8, 2026

there is issue restyle fucked up something probably, quickfix:

    pairs=$(git -C "$path" log -p --oneline --format="GIT: %h" PKGBUILD | grep -e 'GIT:.*' -e '+pkgver' | grep -Pzo 'GIT: .*\n\+pkgver=.*\n' | sed 's/GIT: \|+pkgver=//' | tr -d '\0')

@darukutsu
Copy link
Contributor Author

for some reason missing quoted didn't saw it in head diff when was merging

@darukutsu
Copy link
Contributor Author

how did tests pass tho?

@pbrisbin
Copy link
Member

pbrisbin commented Jan 8, 2026

restyle fucked up something probably

This was what Restyled did, it was only whitespace.

diff --git a/src/downgrade b/src/downgrade
index 84e9bc1..24a3204 100755
--- a/src/downgrade
+++ b/src/downgrade
@@ -211,8 +211,8 @@ search_git() {
     path="$cache/$name" # directory name
     if ! [[ -d "$path/.git" ]]; then
       {
-	gettext "\`$path\" not a git directory, skipping..."
-	echo
+        gettext "\`$path\" not a git directory, skipping..."
+        echo
       } >&2
       continue
     fi
@@ -586,12 +586,11 @@ build_pkg() {
       exit 1
     fi
 
-
     item="$(find "$path" -maxdepth 1 -type f -name "$(sed -nr '/.*Finished making: ([^ ]+) ([^ ]+) .*/{s//\1-\2/;p}' makepkg.log)*" -print -quit)"
     rm makepkg.log
     popd >/dev/null
   fi
-  printf "%s\0" "$item" >> new_to_install.downgrade
+  printf "%s\0" "$item" >>new_to_install.downgrade
 }
 
 cli() {
@@ -611,7 +610,7 @@ cli() {
     for item in "${to_install[@]}"; do
       build_pkg "$item"
     done
-    mapfile -d '' to_install < new_to_install.downgrade
+    mapfile -d '' to_install <new_to_install.downgrade
     rm new_to_install.downgrade
   fi
 
-- 
2.52.0

how did tests pass tho?

🤷

@darukutsu
Copy link
Contributor Author

darukutsu commented Jan 8, 2026

5f75463 this was commit that changed something in downgrade (and is correct) so maybe build?
Edit: yea so everything in repo is correct build must be broken

@darukutsu
Copy link
Contributor Author

darukutsu commented Jan 8, 2026

to be clear:

                                                                                  v --- `missing quote`
    pairs=$(git -C "$path" log -p --oneline --format="GIT: %h" PKGBUILD | grep -e GIT:.*' -e '+pkgver' | grep -Pzo 'GIT: .*\n\+pkgver=.*\n' | sed 's/GIT: \|+pkgver=//' | tr -d '\0')

@pbrisbin
Copy link
Member

pbrisbin commented Jan 8, 2026

build must be broken

You are right. The m4 process that injects version must be mangling quotes. I feel like I've solved that before.

I can try to update the tests so it builds before testing to catch these.

@pbrisbin
Copy link
Member

pbrisbin commented Jan 8, 2026

I'm going to revert and release since this breaks everything. Will bring it back after addressing the CI gap.

@pbrisbin
Copy link
Member

pbrisbin commented Jan 8, 2026

FYI the feature was reverted in 11.7 and brought back in 11.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants