Skip to content

source-hash should display hash of installed version #3567

@Khady

Description

@Khady

When a package is installed from a VCS like git, a source-hash field is displayed by opam show PKG. This hash is the hash of the last commit cloned by opam. It is not the hash of the commit used to install the package. This is miss-leading. Pretty often I run opam update without upgrading. After that it is complicated to know what version of the package is actually installed. I think it would be better to displayed the installed version.

Here is a simple scenario showing the confusing case:

$ ls
demo.opam
$ cat demo.opam 
opam-version: "2.0"
name: "demo"
version: "0.1"
synopsis: "demo"
description: """
demo
"""
maintainer: "Ahrefs <github@ahrefs.com>"
authors: "Ahrefs <github@ahrefs.com>"
homepage: "https://github.com/ahrefs/demo"
bug-reports: "https://github.com/ahrefs/demo/issues"
depends: []
build: ["dune" "build" "-p" name]
$ git init
Initialized empty Git repository in /tmp/opam/g/.git/
$ git add demo.opam 
$ git ci -am "1"
[master (root-commit) 70798f0] 1
 1 file changed, 13 insertions(+)
 create mode 100644 demo.opam
$ opam pin add demo -k git .
Package demo does not exist, create as a NEW package? [Y/n] y
[demo.~dev] synchronised from git+file:///tmp/opam/g#master
[WARNING] Failed checks on demo package definition from source at git+file:///tmp/opam/g#master:
  warning 47: Synopsis should start with a capital and not end with a dot
demo is now pinned to git+file:///tmp/opam/g#master (version 0.1)

The following actions will be performed:
  ∗ install demo 0.1*
Do you want to continue? [Y/n] y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
∗ installed demo.0.1
Done.
$ opam show demo

<><> demo: information on all versions ><><><><><><><><><><><><><><><><><><><><>
name                   demo
all-installed-versions 0.1 [tools]
all-versions           0.1

<><> Version-specific details <><><><><><><><><><><><><><><><><><><><><><><><><>
version      0.1
pin          git+file:///tmp/opam/g#master
source-hash  70798f01
url.src:     "git+file:///tmp/opam/g#master"
homepage:    "https://github.com/ahrefs/demo"
bug-reports: "https://github.com/ahrefs/demo/issues"
authors:     "Ahrefs <github@ahrefs.com>"
maintainer:  "Ahrefs <github@ahrefs.com>"
synopsis     demo
description  demo
$ touch new
$ git add new
$ git ci -am "2"
[master d8ce25f] 2
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 new
$ opam update demo

<><> Synchronising development packages <><><><><><><><><><><><><><><><><><><><>
[demo.0.1] synchronised from git+file:///tmp/opam/g#master
Now run 'opam upgrade' to apply any package updates.
$ opam show demo

<><> demo: information on all versions ><><><><><><><><><><><><><><><><><><><><>
name                   demo
all-installed-versions 0.1 [tools]
all-versions           0.1

<><> Version-specific details <><><><><><><><><><><><><><><><><><><><><><><><><>
version      0.1
pin          git+file:///tmp/opam/g#master
source-hash  d8ce25f3
url.src:     "git+file:///tmp/opam/g#master"
homepage:    "https://github.com/ahrefs/demo"
bug-reports: "https://github.com/ahrefs/demo/issues"
authors:     "Ahrefs <github@ahrefs.com>"
maintainer:  "Ahrefs <github@ahrefs.com>"
synopsis     demo
description  demo
$ opam upgrade demo

<><> Synchronising pinned packages ><><><><><><><><><><><><><><><><><><><><><><>
[demo.0.1] no changes from git+file:///tmp/opam/g#master

The following actions will be performed:
  ↻ recompile demo 0.1*

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⊘ removed   demo.0.1
∗ installed demo.0.1
Done.
$ opam show demo

<><> demo: information on all versions ><><><><><><><><><><><><><><><><><><><><>
name                   demo
all-installed-versions 0.1 [tools]
all-versions           0.1

<><> Version-specific details <><><><><><><><><><><><><><><><><><><><><><><><><>
version      0.1
pin          git+file:///tmp/opam/g#master
source-hash  d8ce25f3
url.src:     "git+file:///tmp/opam/g#master"
homepage:    "https://github.com/ahrefs/demo"
bug-reports: "https://github.com/ahrefs/demo/issues"
authors:     "Ahrefs <github@ahrefs.com>"
maintainer:  "Ahrefs <github@ahrefs.com>"
synopsis     demo
description  demo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions