Using git from a program

I am trying to snap https://github.com/nifty-site-manager/nsm-snap and everything seems to be working except for where my program needs to call git to clone or push. When it tries to do that the program outputs fatal: Unable to find remote helper for 'https'. I have added libcurl4-openssl-dev as a stage-package hoping that would fix the problem with git but unfortunately it does not (I tried curl-devel as well but it couldn’t find the package).

Does anyone know how to fix the problem? Thanks for reading/helping.

Also once it is working how do I get it to publish properly to the snap store? Do I just change confinement to classic? (it needs to be able to access the users files)

1 Like

You may find this example git snap useful: git-snap/snap/snapcraft.yaml at master · anonymouse64/git-snap · GitHub

I don’t exactly remember why I wasn’t able to get it working with the version of git from the archive, but perhaps all you need are just the environment variables.

Try following the guide we have here: https://snapcraft.io/docs/releasing-to-the-snap-store

You should try to use the home and removable-media interfaces with strict confinement before using classic; for most cases these interfaces are sufficient and classic confinement is unnecessary. Should you find that you do need classic confinement for your snap, see the process documented at Process for reviewing classic confinement snaps for how to go about requesting that.

I have tried adding in those environment variables and still have the same problem fatal: Unable to find remote helper for 'https', does anyone else have any suggestions? Does anyone else have a project that has to call git clone/push?

inside your snap, what’s in the git-core directory?

Edit to add: if you look at icdiff’s snapcraft.yaml you’ll see that between the organize and stage sections it arranges to copy git and those bits of git-core that it needs for the operations it does. You’d likely need to do the same. Maybe try copying all of git-core, and then pruning back to keep things tight.

There’s snap/nsm/114/usr/share/git-core/ which contains contrib and templates.

nothing else? no git-http-fetch for example?

Nope, nothing else at all… That’s the only place I can find git-core too…

ok, so that’s probably what you’re missing.

Any idea how I can get it? I am clueless there… Currently testing if git-all works…

it looks like you’re not packaging git at all, so start by doing that. Again if you look at the icdiff yaml, look at the ppa part (so you get the latest git), and then in the icdiff part look at stage-packages as well as the aforementioned organise and stage sections.

to get git working, I believe you need the following in your yaml:

parts:
  ...
  some-part:
    ...
    stage-packages:
    - git-core

...
environment:
  GIT_EXEC_PATH: $SNAP/usr/lib/git-core

The ... indicates that there’s a lot that I’ve omitted for brevity.

1 Like

That’s got it working Daniel, thanks a tonne!

1 Like

@ijohnson I now have it working in confinement devmode and am trying to get it published to stable.

When I change confinement to strict and install using snap install --edge nsm it installs but cannot create/delete/open files as needed (it still works fine when I do snap install --edge --devmode nsm). How do I use the home and removable-media interfaces with strict confinement? Anyone else reading happen to know the answer?

The home and removable-media interfaces should auto-connect if you are running on a classic distro (i.e. not on Ubuntu Core) and if they are specified in your snapcraft.yaml.

You will need to modify your app to something like the following to declare the interfaces:

apps:
  nsm:
    command: nsm
    plugs:
      - home
      - removable-media
    environment:
      LD_LIBRARY_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio
      DISABLE_WAYLAND: '1'
      GIT_TEMPLATE_DIR: $SNAP/usr/share/git-core/templates
      GIT_EXEC_PATH: $SNAP/usr/lib/git-core

you probably want to keep the original LD_LIBRARY_PATH here and extend it instead of replacing …:

LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio

(might need some quoting though)

I can now create/delete/open files as needed when using snap install --edge nsm, however when I try to use git clone/push I am getting for example fatal: unable to access 'https://gitlab.com/pokebots/parchment-site.git/': Could not resolve host: gitlab.com.

It works fine when I use snap install --edge --devmode nsm. Anyone got any suggestions on what might be causing it? Would perhaps classic confinement be the solution?

Edit: Am heading to bed, will try people’s suggestions in the morning. Otherwise is there a way to get the install pages to tell people to use snap install --edge --devmode nsm?

Nobody has any ideas?

Do you get any denials in journalctl -e --no-pager | grep DENIED when you run it without devmode?

I get Unprivileged users cannot access messages, unless persistent log storage is enabled. Users in the 'systemd-journal' group may always access messages. Both from --edge and from --edge --devmode.

Both output nothing if I run them with sudo.

I have tried using git-all as the stage package rather than git-core and still no love. Anyone got any other suggestions to try? Would it be worth trying classic confinement?