Skip to content

Commit

Permalink
tools/op: add switch command (commaai#34112)
Browse files Browse the repository at this point in the history
* tools/op: add switch command

* fix

* .

* usage

* fix

---------

Co-authored-by: Maxime Desroches <[email protected]>
  • Loading branch information
adeebshihadeh and maxime-desroches authored Dec 3, 2024
1 parent 4380774 commit b334412
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tools/op.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function op_check_git() {
fi

echo "Checking for git lfs files..."
if [[ $(file -b $OPENPILOT_ROOT/selfdrive/modeld/models/supercombo.onnx) == "data" ]]; then
if [[ $(file -b $OPENPILOT_ROOT/selfdrive/modeld/models/dmonitoring_model.onnx) == "data" ]]; then
echo -e " ↳ [${GREEN}${NC}] git lfs files found."
else
echo -e " ↳ [${RED}${NC}] git lfs files not found! Run 'git lfs pull'"
Expand Down Expand Up @@ -312,6 +312,30 @@ function op_sim() {
op_run_command exec tools/sim/launch_openpilot.sh
}

function op_switch() {
op_before_cmd

REMOTE="origin"
if [ "$#" -gt 1 ]; then
REMOTE="$1"
shift
fi

if [ -z "$1" ]; then
echo -e "${BOLD}${UNDERLINE}Usage:${NC} op switch [REMOTE] <BRANCH>"
return 1
fi
BRANCH="$1"

git fetch "$REMOTE" "$BRANCH":"$BRANCH"
git checkout -f --recurse-submodules "$BRANCH"
git reset --hard "$BRANCH"
git clean -df
git submodule update --init --recursive
git submodule foreach git reset --hard
git submodule foreach git clean -df
}

function op_default() {
echo "An openpilot helper"
echo ""
Expand All @@ -333,6 +357,7 @@ function op_default() {
echo -e " ${BOLD}setup${NC} Install openpilot dependencies"
echo -e " ${BOLD}build${NC} Run the openpilot build system in the current working directory"
echo -e " ${BOLD}install${NC} Install the 'op' tool system wide"
echo -e " ${BOLD}switch${NC} Switch to a different git branch with a clean slate (nukes any changes)"
echo ""
echo -e "${BOLD}${UNDERLINE}Commands [Tooling]:${NC}"
echo -e " ${BOLD}juggle${NC} Run PlotJuggler"
Expand Down Expand Up @@ -388,6 +413,7 @@ function _op() {
replay ) shift 1; op_replay "$@" ;;
sim ) shift 1; op_sim "$@" ;;
install ) shift 1; op_install "$@" ;;
switch ) shift 1; op_switch "$@" ;;
post-commit ) shift 1; op_install_post_commit "$@" ;;
* ) op_default "$@" ;;
esac
Expand Down

0 comments on commit b334412

Please sign in to comment.