blob: 8df388b8bc89e640a32b19653f2d7ffcb9873ca2 [file] [log] [blame] [edit]
#!/bin/bash
# Copyright 2025 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#### CATEGORY=Source
### Run git commands in the Fuchsia tree.
##
## usage: fx git get-rev [--repo_root <repo>]
## get-rev Get the current git revision of the Fuchsia checkout. If no
## --repo_root is pass in, we will use "fuchsia" as default value.
##
## Sample usage:
##
## $ fx git get-rev (This will get the HEAD of fuchsia repo)
## $ fx git get-rev --repo_root third_party/icu/default (This will get the
## HEAD of third_party/icu/default repo)
set -o errexit
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
source "${SCRIPTS_DIR}/lib/vars.sh" || exit $?
function cmd_get_rev() {
local repo_root=""
while [[ $# -ge 1 ]]; do
case "$1" in
--repo_root)
shift
repo_root="$1"
;;
*)
fx-error "Unknown argument for get-rev: $1"
exit 1
;;
esac
shift
done
"${SCRIPTS_DIR}/lib/get_fuchsia_subdir_git_revision.sh" "${FUCHSIA_DIR}" "${repo_root}"
}
main() {
local subcommand="$1"
shift
case "${subcommand}" in
get-rev)
cmd_get_rev "$@"
;;
*)
fx-error "Unknown command: git ${subcommand}"
exit 1
;;
esac
}
main "$@"