|
72 | 72 |
|
73 | 73 | git checkout "$TARGET_BRANCH" |
74 | 74 |
|
| 75 | + # Preserve the license header from the existing .settings.xml before overwriting, |
| 76 | + # so that e.g. an Apache header on an OSS-derived branch is not replaced by the |
| 77 | + # Broadcom header present in the commercial default branch. |
| 78 | + if [[ -f "$SETTINGS_FILE" ]]; then |
| 79 | + node -e " |
| 80 | + const fs = require('fs'); |
| 81 | + const content = fs.readFileSync('.settings.xml', 'utf8'); |
| 82 | + const m = content.match(/<!--[\s\S]*?-->/); |
| 83 | + if (m) fs.writeFileSync('/tmp/_preserved_header.txt', m[0]); |
| 84 | + " 2>/dev/null || true |
| 85 | + if [[ -s /tmp/_preserved_header.txt ]]; then |
| 86 | + echo "Preserved existing license header from '${TARGET_BRANCH}:${SETTINGS_FILE}'." |
| 87 | + else |
| 88 | + rm -f /tmp/_preserved_header.txt |
| 89 | + fi |
| 90 | + fi |
| 91 | +
|
75 | 92 | # Remove any existing .settings.xml on the target branch |
76 | 93 | if [[ -f "$SETTINGS_FILE" ]]; then |
77 | 94 | echo "Removing existing ${SETTINGS_FILE} from '${TARGET_BRANCH}'..." |
|
82 | 99 | echo "Copying ${SETTINGS_FILE} from '${SOURCE_BRANCH}' to '${TARGET_BRANCH}'..." |
83 | 100 | git show "origin/${SOURCE_BRANCH}:${SETTINGS_FILE}" > "$SETTINGS_FILE" |
84 | 101 |
|
| 102 | + # Restore the preserved license header if we captured one |
| 103 | + if [[ -f /tmp/_preserved_header.txt ]]; then |
| 104 | + echo "Restoring preserved license header..." |
| 105 | + node -e " |
| 106 | + const fs = require('fs'); |
| 107 | + const content = fs.readFileSync('.settings.xml', 'utf8'); |
| 108 | + const header = fs.readFileSync('/tmp/_preserved_header.txt', 'utf8'); |
| 109 | + const updated = content.replace(/<!--[\s\S]*?-->/, header); |
| 110 | + fs.writeFileSync('.settings.xml', updated); |
| 111 | + " |
| 112 | + fi |
| 113 | +
|
85 | 114 | git add "$SETTINGS_FILE" |
86 | 115 |
|
87 | 116 | if git diff --cached --quiet; then |
|
0 commit comments