Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve conflit between Tchap and Element Web 1.11.25 #475

Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
197effe
Resolve conflit between Tchap and Element Web 1.11.25
jdauphant Mar 17, 2023
04f0575
Add patch-package to package.json
jdauphant Mar 17, 2023
13831b0
Move patches temporary to other path
jdauphant Mar 17, 2023
b514b15
Remove unnecessary patch
jdauphant Mar 17, 2023
f9aba8d
Fix patch-package position in package.json
jdauphant Mar 17, 2023
2535379
Move back patches-unfixed to patches
jdauphant Mar 19, 2023
5a1652f
Add merge script
jdauphant Mar 19, 2023
4a5ed6e
Adaptation of 15 patches
jdauphant Mar 19, 2023
c9dbbaf
Update merge Script
jdauphant Mar 20, 2023
1a0898e
Adapt Hide Location patch
jdauphant Mar 20, 2023
174f6ee
Remove patch user-friendlier-encrypted-messages
jdauphant Mar 20, 2023
20d7024
activate-cross-signing-and-secure-storage-react - to test : checkDevi…
odelcroi Mar 20, 2023
328aaca
add-a-help-tab-in-menu-to-redirect-to-external-tchap-faq
odelcroi Mar 20, 2023
4e595d4
remove old patch activate-cross-signing-and-secure-storage-react
odelcroi Mar 20, 2023
3d76023
patch : auto-accept-tac
odelcroi Mar 20, 2023
faa51ec
update patch better-help-settings
odelcroi Mar 20, 2023
f49bc05
update patch : cross signing ui
odelcroi Mar 20, 2023
21f740a
patch update : disable-access-options
odelcroi Mar 20, 2023
75e1bd9
update patch : forgot-password, removed one file from patch
odelcroi Mar 20, 2023
1a23b4e
remove old patch : hide-location-if-no-map-server
odelcroi Mar 20, 2023
d15d124
update patch : login
odelcroi Mar 20, 2023
2a5379d
Adapt patch simplify-exchange-key-message
jdauphant Mar 20, 2023
953cb3d
update patch : password-policy
odelcroi Mar 20, 2023
70e06b0
Merge branch 'upgrade/element-web-v1.11.25-resolv-conflict' of https:…
odelcroi Mar 20, 2023
31c6fa3
restore Tchap configuration
odelcroi Mar 20, 2023
c654148
remove lint error
odelcroi Mar 20, 2023
2f3a21c
change version to 4.2.0
odelcroi Mar 20, 2023
21d8f8d
remove conf files from eslint
odelcroi Mar 20, 2023
fc3de71
reactivate patch
odelcroi Mar 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions scripts/merge-patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/bash

set -e

# Variables
PROJECT_DIR=$(pwd)
PACKAGE_JSON="$PROJECT_DIR/package.json"
PATCHES_DIR="$PROJECT_DIR/patches"
TEMP_DIR="$PROJECT_DIR/temp"

function merge_patches() {
odelcroi marked this conversation as resolved.
Show resolved Hide resolved
CONFLICTS_FOUND=false

# Iterate through the patch files
for PATCH_PATH in "$PATCHES_DIR"/*/*.patch; do
PATCH_DIR=$(basename "$(dirname "$PATCH_PATH")")
PATCH_FILE=$(basename $PATCH_PATH)
PACKAGE_NAME=$(echo "$PATCH_FILE" | cut -d'+' -f1)
PACKAGE_VERSION=$(jq -r ".dependencies.\"$PACKAGE_NAME\"" "$PACKAGE_JSON")
echo "# Manage $PATCH_PATH"

# Check if the package version exists and if the patch needs to be updated
if [ "$PACKAGE_VERSION" == "null" ] || [[ "$PATCH_FILE" =~ "$PACKAGE_NAME+$PACKAGE_VERSION".patch ]]; then
echo "Package '$PACKAGE_NAME' not found in package.json or patch already up-to-date. Skipping patch update."
continue
fi

# Create a subfolder for the current package inside the temporary directory
PACKAGE_TEMP_DIR="$TEMP_DIR/$PATCH_DIR"
mkdir -p "$PACKAGE_TEMP_DIR"
LOG_FILE=$PACKAGE_TEMP_DIR/result.log

# Install the package in the package subfolder
cd "$PACKAGE_TEMP_DIR"
echo '{ }' > package.json
yarn add "$PACKAGE_NAME@$PACKAGE_VERSION" > $LOG_FILE 2>&1
yarn add patch-package > $LOG_FILE 2>&1

# Apply the patch with --merge option
patch -p1 --no-backup-if-mismatch --input="$PATCH_PATH" --forward --merge 2>&1 > $LOG_FILE || true

# Check for conflicts
CONFLICTS=$(grep -lr "<<<<<<<" node_modules/"$PACKAGE_NAME") || true

# If there are conflicts, inform the user
if [ -n "$CONFLICTS" ]; then
echo "There were conflicts when applying the patch to $PACKAGE_NAME@$PACKAGE_VERSION."
echo "Resolve the conflicts manually and run the script again with the 'continue' command."
echo "Conflicted files:"
echo "$CONFLICTS"
CONFLICTS_FOUND=true
else
# If there are no conflicts, generate a new patch file
yarn patch-package "$PACKAGE_NAME" > $LOG_FILE 2>&1

# Move the new patch file to the old patch file's location
mv patches/"$PACKAGE_NAME"*.patch "$(dirname $PATCH_PATH)"
rm $PATCH_PATH

# Clean up the package subfolder
cd "$TEMP_DIR"
rm -rf "$PATCH_DIR"
echo "Patch Done and temp file cleaned"
fi
echo ""
done

if [ "$CONFLICTS_FOUND" = false ]; then
echo "All patches have been updated without conflicts."
clean_temp_dir
else
echo "Some patches have conflicts. After resolving the conflicts, run the script again with the 'continue' command."
fi
}

function continue_patches() {
odelcroi marked this conversation as resolved.
Show resolved Hide resolved
CONFLICTS_FOUND=false

# Iterate through the package subfolders
for PACKAGE_TEMP_DIR in "$TEMP_DIR"/*; do
echo "# Manage $PATCH_PATH"
PATCH_DIR="$PATCHES_DIR/$(basename "$PACKAGE_TEMP_DIR")"
PATCH_PATH="$PATCH_DIR"/*.patch
PATCH_FILE=$(basename $PATCH_PATH)
PACKAGE_NAME=$(echo "$PATCH_FILE" | cut -d'+' -f1)

# Check for conflicts
CONFLICTS=$(grep -lr "<<<<<<<" "$PACKAGE_TEMP_DIR/node_modules/$PACKAGE_NAME") || true

# If there are conflicts, inform the user
if [ -n "$CONFLICTS" ]; then
echo "There are still conflicts in the patch for $PACKAGE_NAME."
echo "Resolve the conflicts manually and run the script again with the 'continue' command."
echo "Conflicted files:"
echo "$CONFLICTS"
CONFLICTS_FOUND=true
else
# If there are no conflicts, generate a new patch file
cd "$PACKAGE_TEMP_DIR"
yarn patch-package "$PACKAGE_NAME"

# Move the new patch file to the old patch file's location
mv patches/"$PACKAGE_NAME"*.patch "$(dirname $PATCH_PATH)"

# Clean up the package subfolder
cd "$TEMP_DIR"
rm -rf "$(basename "$PACKAGE_TEMP_DIR")"
fi
done

if [ "$CONFLICTS_FOUND" = false ]; then
echo "All patches have been updated successfully."
# Remove the temporary directory
cd "$PROJECT_DIR"
clean_temp_dir
else
echo "Some patches still have conflicts. Resolve them and run the script again with the 'continue' command."
fi
}

function clean_temp_dir() {
rm -rf "$TEMP_DIR"
}

# Check the command line argument for "merge", "continue", or "clean"
if [ "$#" -ne 1 ]; then
echo "Usage: $0 {merge|continue|clean}"
exit 1
fi

if [ "$1" == "merge" ]; then
merge_patches
elif [ "$1" == "continue" ]; then
continue_patches
elif [ "$1" == "clean" ]; then
clean_temp_dir
else
echo "Invalid command. Usage: $0 {merge|continue|clean}"
exit 1
fi