Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Store git repository information in ebuild [SOLVED]

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
5 posts • Page 1 of 1
Author
Message
Zucca
Moderator
Moderator
User avatar
Posts: 4681
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

Store git repository information in ebuild [SOLVED]

  • Quote

Post by Zucca » Mon Feb 12, 2024 7:54 pm

I've faced some problems with git and ebuild creation.
I have written my own git-extra.eclass. It inherits git-r3.eclass and then adds a function which runs few git commands to retrieve commit hash and tag (if any) and put that information in the package doc directory. I've made this because it's then easy to create new ebuild from installed -9999 live version.

However something has changed and running git commands to query the information will error out:

Code: Select all

fatal: detected dubious ownership in repository at '/var/tmp/portage/dev-games/eureka-1.27-r1/work/eureka-1.27'                                                                                                                                
To add an exception for this directory, call:                                                                                                                                                                                                  
                                                                                                                                                                                                                                               
        git config --global --add safe.directory /var/tmp/portage/dev-games/eureka-1.27-r1/work/eureka-1.27
... if I run the command above (but without --global, for obvious reasons) I get:

Code: Select all

fatal: not in a git directory
The function inside my eclass for the curious ones:

Code: Select all

git_nfo() {
        local git_nfo_file="${T%/}/git_version.nfo"
        local TAG CNUM

        [[ ! -f "$git_nfo_file" ]] && {
                TAG="$(git tag --list --sort=-version:refname | head -n 1)"
                echo "tag: ${TAG:-"[notag]"}"
                CNUM="$(git rev-list --count ${TAG:+${TAG}..}HEAD)"
                echo "commit number (since tag): ${CNUM}"
                echo "commit: $(git rev-parse HEAD)"
                echo "PF: ${PN}-${TAG}_p${CNUM}"
        } > "$git_nfo_file"

        case "$1" in
                install)
                        if [[ "$2" ]]
                        then
                                newdoc "$git_nfo_file" "$2"
                        else
                                dodoc "$git_nfo_file"
                        fi
                ;;
                *)
                        cat "$git_nfo_file"
                ;;
        esac
}
Any tips to get git commands work again, or alternatively how to get the information what the function above used to retrieve?
Last edited by Zucca on Tue Feb 13, 2024 4:30 pm, edited 1 time in total.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
hdcg
Tux's lil' helper
Tux's lil' helper
Posts: 122
Joined: Sun Apr 07, 2013 8:30 am

  • Quote

Post by hdcg » Tue Feb 13, 2024 11:37 am

Hi Zucca,

since a few updates git warns and rejects to work if (at least) the root user tries to execute a git command within a repository not owned by the running user.
I guess emerge runs the install phase as root and everything else as the portage user.

The message

Code: Select all

fatal: not in a git directory
indicates git is running outside a git repository, but needs a repository for the requested command. In your case omitting the --global flag, instructs git to change the repository settings, hence the error.

I suggest to move the extract part from install to prepare or compile phase. Then it should work again.

Best Regards,
Holger
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4681
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Tue Feb 13, 2024 11:47 am

hdcg wrote:I guess emerge runs the install phase as root and everything else as the portage user.
Yes. That's the probable cause of the error. Thanks.
hdcg wrote: The message

Code: Select all

fatal: not in a git directory
indicates git is running outside a git repository, but needs a repository for the requested command. In your case omitting the --global flag, instructs git to change the repository settings, hence the error.
I specifically made sure to pass the right directory (even an absolute path) for the command. Do you suspect that the current working directory needs to be also inside the repository directory?

I'll try to adjust my eclass...
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Hu
Administrator
Administrator
Posts: 24380
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Tue Feb 13, 2024 3:44 pm

Zucca wrote:I specifically made sure to pass the right directory (even an absolute path) for the command. Do you suspect that the current working directory needs to be also inside the repository directory?
Yes. The command as shown tells git what to trust. It does not tell it where to store that trust, so we follow the standard git rules. If none of the location flags are specified, git defaults to storing in the local git repository. If the current working directory is not a repository and you have not otherwise told it how to find a repository, then it fails saying you are not in a local git repository.

Also, for this particular git configuration, I expect putting it in the local repository will be ignored. Per the documentation, git is refusing to work with a repository owned by a foreign user. If that user could mark the repository as safe, then what would stop every malicious repository from flagging itself as safe?
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4681
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Tue Feb 13, 2024 4:30 pm

I added pushd "${S}" and popd in the beginning and the end of the function and it does now work.
Thanks for you both!
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Post Reply

5 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy