| #!/bin/bash |
| # Copyright 2020 The ChromiumOS Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| # |
| # ./merge_main |
| # Merge m/main to current workspace, and reset the merged result as |
| # (p1=m/main, p2=current:p2) with the same commit message. |
| # This can be used to update the current commit when m/main has new changes |
| # during uprev work period. |
| PARENT=$(git cat-file commit HEAD | egrep '^parent' | tail -n 1 | cut -d' ' -f2) |
| MSG="$(git cat-file commit HEAD | tail -n +7)" |
| # Extract author from the commit message with reformatting as follows: |
| # author First Last <user@chromium.org> 1622110244 +0900 => First Last <user@chromium.org> |
| AUTHOR="$(git cat-file commit HEAD | grep '^author' | head -n 1 | sed -e 's/^author \(.*\) [0-9]* [-+][0-9]*/\1/g')" |
| AUTHOR_NAME="$(echo "$AUTHOR" | sed -e 's/ <.*>//g')" |
| AUTHOR_EMAIL="$(echo "$AUTHOR" | sed -e 's/.*<\(.*\)>/\1/g')" |
| |
| git merge m/main |
| (source ~/.bashrc; env PS1="change >" bash --norc) |
| |
| TREE=$(git cat-file commit HEAD | egrep '^tree' | cut -d' ' -f2) |
| NEW=$(GIT_AUTHOR_NAME="$AUTHOR_NAME" GIT_AUTHOR_EMAIL="$AUTHOR_EMAIL" git commit-tree "$TREE" -p m/main -p "$PARENT" < <(echo "$MSG")) |
| git reset --hard "$NEW" |