From c867fd49cecbf0c431f89c6303b0e431592d9dae Mon Sep 17 00:00:00 2001 From: Phil Adams Date: Tue, 13 Aug 2024 10:06:30 -0500 Subject: [PATCH] feat: add fix-copyrights.sh script (#254) Signed-off-by: Phil Adams --- scripts/fix-copyrights.sh | 27 +++++++++++++++++++++++++++ update_service.md | 23 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 scripts/fix-copyrights.sh diff --git a/scripts/fix-copyrights.sh b/scripts/fix-copyrights.sh new file mode 100755 index 0000000000..f832baf149 --- /dev/null +++ b/scripts/fix-copyrights.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# * Copyright 2017 - 2024 IBM Corporation. +# * SPDX-License-Identifier: Apache2.0 +# + +# +# The purpose of this script is to revert changes to generated files where the file changed +# only in the copyright statement (i.e. no other differences in the file contents). +# +# Run this script in a git repo containing uncommitted changes produced from SDK generation. +# +# Usage: +# /scripts/fix-copyrights.sh +# + +git diff --name-only | while read f; do + # Must be only one line added and one deleted + git diff --shortstat "$f" | grep "1 insertion(+), 1 deletion(-)" > /dev/null + if [ $? == 0 ]; then + git diff "$f" | grep "(C) Copyright IBM Corp\. 20[0-9][0-9]." > /dev/null + if [ $? == 0 ]; then + echo "Reverting copyright change in $f" + git checkout -- "$f" + fi + fi +done diff --git a/update_service.md b/update_service.md index 7254ea0982..02a9fd4547 100644 --- a/update_service.md +++ b/update_service.md @@ -130,6 +130,29 @@ Example: git diff # alternative: use the "source control" view within vscode ``` +#### Revert insignificant changes +When the Java SDK code for a service is re-generated, it is not uncommon for some generated classes +(especially model classes) to see changes only in their copyright statements, with no other changes +to their generated source. + +These types of changes are insignificant, and they can (and to some degree should), be reverted. +Reverting these changes will help to avoid cluttering your PRs and git change history, +and in some respects the copyright year should not be changed if no other changes are being made to the file. +Unfortunately, it's difficult for the generator to operate this way so it simply re-generates all classes +associated with a service and if this re-generation is occurring in a different year than the previous +generation, then you'll see the change to the copyright statement. + +To automatically revert these changes, just run the `fix-copyrights.sh` script +in the project root directory: +``` +cd +scripts/fix-copyrights.sh +``` +The script will examine each file with uncommitted changes, and for those files with changes +only in their copyright statement, a `git checkout` is performed to +discard the changes and revert the files to their pervious version. + + ### 5. Run unit tests Next, run the unit tests. You can run the unit tests for all the services like this: ```sh