fix: fetch base branch before performing merge-base

Also make sure the copright script honors the refspec that's passed on
it's command line.

Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
Change-Id: I91250c39015129c3c1eef0891ff55ee2ea6f74b1
diff --git a/script/static-checks/check-copyright.py b/script/static-checks/check-copyright.py
index ff124fb..cd0167a 100755
--- a/script/static-checks/check-copyright.py
+++ b/script/static-checks/check-copyright.py
@@ -194,20 +194,9 @@
 Instead of checking all files in the source tree, the script will consider
 only files that are modified by the latest patch(es).""",
                         action="store_true")
-
-    (rc, stdout, stderr) = utils.shell_command(['git', 'merge-base', 'HEAD', 'refs/remotes/origin/tfa-next'])
-    if rc:
-        print("Git merge-base command failed. Cannot determine base commit.")
-        sys.exit(rc)
-    merge_bases = stdout.splitlines()
-
-    # This should not happen, but it's better to be safe.
-    if len(merge_bases) > 1:
-        print("WARNING: Multiple merge bases found. Using the first one as base commit.")
-
     parser.add_argument("--from-ref",
                         help="Base commit in patch mode (default: %(default)s)",
-                        default=merge_bases[0])
+                        default="remotes/origin/integration")
     parser.add_argument("--to-ref",
                         help="Final commit in patch mode (default: %(default)s)",
                         default="HEAD")
diff --git a/script/static-checks/common.sh b/script/static-checks/common.sh
index 0f76b10..d7a56b7 100644
--- a/script/static-checks/common.sh
+++ b/script/static-checks/common.sh
@@ -4,11 +4,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
-function get_base_branch() {
-    # Remove prefix
-    echo origin/${GERRIT_BRANCH#refs/heads/}
-}
-
 function get_merge_base() {
-    git merge-base HEAD $(get_base_branch) | head -1
+    git fetch origin ${GERRIT_BRANCH#refs/heads/}
+    git merge-base HEAD FETCH_HEAD | head -1
 }
diff --git a/script/static-checks/static-checks-coding-style-line-endings.sh b/script/static-checks/static-checks-coding-style-line-endings.sh
index 66763bc..7e25f64 100755
--- a/script/static-checks/static-checks-coding-style-line-endings.sh
+++ b/script/static-checks/static-checks-coding-style-line-endings.sh
@@ -22,7 +22,7 @@
     shopt -s globstar
     parent=$(get_merge_base)
     git diff $parent..HEAD --no-ext-diff --unified=0 --exit-code -a \
-      --no-prefix **/*.{S,c,h,i,dts,dtsi,rst,mk,rs} Makefile | \
+      --no-prefix **/{Makefile,*.{S,c,h,i,dts,dtsi,rst,mk,rs}} | \
       awk '/^\+/ && /\r$/' &> "$LOG_FILE"
 else
   # For all the source and doc files