xref: /aosp_15_r20/external/linux-firmware/run_copybara.sh (revision 2764adbb83be75699e7e173cb61cdbf8f430c544)
1#!/bin/bash
2#
3# Script to invoke copybara to generate an 'IMPORT:' change for linux-firmware.
4#
5# Copyright (C) 2024 The Android Open Source Project
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11#      http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18
19set -e
20
21die () {
22	>&2 echo "$1"
23	exit 1
24}
25
26fw_name="$1"
27if [[ -z "${fw_name}" ]]; then
28	die "Usage: $0 [fw_name]"
29fi
30
31# Save the name of the current branch so we can get back to it.
32copybara_branch="$(git branch --show-current)"
33if [[ -z "${copybara_branch}" ]]; then
34	die "You must be on a branch before running"
35fi
36
37# If something fails go back to the branch we were on.
38trap "git checkout '${copybara_branch}'" EXIT
39
40# We're going to tell copybara to "push" to our branch. That fails
41# if it's already checked out, so checkout the same location but
42# without a branch name
43git checkout --detach
44
45# Run copybara
46copybara --force migrate copy.bara.sky \
47	--git-destination-url="$(dirname "$(readlink -f "$0")")" \
48	--git-destination-push="${copybara_branch}" \
49	"${fw_name}"
50
51git checkout "${copybara_branch}"
52
53# Get a Change-Id added.
54git commit --amend --no-edit
55