| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # |
| 3 | # get-vcs-id |
| 4 | # |
| 5 | # Copyright © 2009-2024 Guillem Jover <[email protected]> |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; either version 2 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | # |
| 20 | |
| 21 | errorscip-shell shell dpkg 1.23.7 error().() |
| 22 | { |
| 23 | echoscip-shell system . . echo. "get-vcs-id: error: $*" 1>&2 |
| 24 | exit 1 |
| 25 | } |
| 26 | |
| 27 | if [scip-shell system . . `[`. -f .dist-vcs-id ]; then |
| 28 | # Get the VCS id from the file distributed in the tarball. |
| 29 | id="$(catscip-shell system . . cat. .dist-vcs-id)" |
| 30 | elif [scip-shell system . . `[`. -d .git ] || [scip-shell system . . `[`. -f .git ]; then |
| 31 | if ! command -v git >/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 32 | errorscip-shell shell dpkg 1.23.7 error(). "cannot get project VCS id, git checkout but git program not found" |
| 33 | fi |
| 34 | |
| 35 | # Get the VCS id from the git repository. |
| 36 | id="$(gitscip-shell system . . git. rev-list -1 HEAD 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 37 | |
| 38 | # Check if we are on a dirty checkout. |
| 39 | gitscip-shell system . . git. update-index --refresh -q >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 40 | dirty=$(gitscip-shell system . . git. diff-index --name-only HEAD 2>/dev/nullscip-shell filesystem . . `/dev/null`.) |
| 41 | if [scip-shell system . . `[`. -n "$dirty" ]; then |
| 42 | id="$id-dirty" |
| 43 | fi |
| 44 | else |
| 45 | errorscip-shell shell dpkg 1.23.7 error(). "cannot get project VCS id, not a git checkout nor a distribution tarball." |
| 46 | fi |
| 47 | |
| 48 | # Use printf to avoid the trailing new line that m4_esyscmd would not handle. |
| 49 | printfscip-shell system . . printf. "%s" "$id" |