Help with git for testing Addon Manager

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Help with git for testing Addon Manager

Post by chennes »

I'm writing some tests for the Addon Manager, and of course one of the things that I want to test is checking for updates. In the context of a unit test, what I need to do is check out some Addon at some past revision, and then make git think that rather than being in a detached head state, it is just out-of-date. Or something equivalent. Can anyone who is better at git than me give me some pointers to how to achieve something like that?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Help with git for testing Addon Manager

Post by adrianinsaval »

how about

Code: Select all

git reset --hard {commit_hash}
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Help with git for testing Addon Manager

Post by openBrain »

To my knowledge, you can only achieve this in a branch.
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Help with git for testing Addon Manager

Post by chennes »

adrianinsaval wrote: Tue Aug 09, 2022 7:28 pm how about

Code: Select all

git reset --hard {commit_hash}
When I try that, "git fetch" doesn't return anything, it acts like it is up-to-date.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Help with git for testing Addon Manager

Post by openBrain »

Is that a problem to use a branch for the test?

Code: Select all

git checkout @^1 -B test_branch
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Help with git for testing Addon Manager

Post by adrianinsaval »

chennes wrote: Tue Aug 09, 2022 8:23 pm When I try that, "git fetch" doesn't return anything, it acts like it is up-to-date.
well fetching is not the correct way to check for updates, you need to compare the remote to the local checked out state, what if I run git fetch on an outdated addon? the checked out copy remains outdated but if I run git fetch again I'll get nothing.
openBrain wrote: Tue Aug 09, 2022 8:48 pm Is that a problem to use a branch for the test?

Code: Select all

git checkout @^1 -B test_branch
git fetch would still return nothing so it's no different than git reset --hard

If you really want to have git fetch return something again I think you can do this:

Code: Select all

git update-ref refs/remotes/origin/master refs/remotes/origin/master@{1}
taken from here: https://stackoverflow.com/questions/152 ... -git-fetch
Last edited by adrianinsaval on Tue Aug 09, 2022 9:12 pm, edited 1 time in total.
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Help with git for testing Addon Manager

Post by chennes »

Yeah, I wasn't sure if the original author had some particular reason to use fetch, though, so I didn't change it. I was hoping to test the code as-is before I did anymore refactoring, but it seems like that's not feasible, I am having to refactor just to enable testing! Oh well...
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Help with git for testing Addon Manager

Post by chennes »

openBrain wrote: Tue Aug 09, 2022 8:48 pm Is that a problem to use a branch for the test?

Code: Select all

git checkout @^1 -B test_branch
In git isn't one always technically on a branch? Anyway, that type of checkout lands you in a detached head state, doesn't it?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Help with git for testing Addon Manager

Post by chennes »

adrianinsaval wrote: Tue Aug 09, 2022 8:53 pm you need to compare the remote to the local checked out state
Using which command?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Help with git for testing Addon Manager

Post by chennes »

Oh sorry -- although it does do a fetch every time, it's really looking at the output of git status to determine the up-to-date status. Nevertheless, if I specifically reset to a specific revision, git status returns nothing.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply