Skip to content

Commit 0b4f26e

Browse files
committed
fix: Correct box alignment and three-way merge for symlinked configs (v2)
1 parent fccd1b8 commit 0b4f26e

1 file changed

Lines changed: 38 additions & 11 deletions

File tree

update.sh

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,10 @@ three_way_merge() {
777777
local config_name="$1" # e.g., "i3/config"
778778
local user_file="$2" # User's current file
779779
local new_file="$3" # New version from repo
780-
local original_file="$4" # Original file (pre-update repo version)
780+
local original_file="$4" # Original file (pre-update repo version, contains user's changes if any)
781781

782-
# If user file doesn't exist or is a symlink, just use new version
783-
if [ ! -f "$user_file" ] || [ -L "$user_file" ]; then
782+
# If user file doesn't exist, just use new version
783+
if [ ! -f "$user_file" ] && [ ! -L "$user_file" ]; then
784784
return 0
785785
fi
786786

@@ -789,7 +789,20 @@ three_way_merge() {
789789
return 1
790790
fi
791791

792-
# Check if user modified the file
792+
# Handle symlinks: compare original (user's version before git reset) vs new
793+
# If user_file is a symlink, the user was editing the repo file directly
794+
# original_file contains what the user had, new_file has upstream changes
795+
if [ -L "$user_file" ]; then
796+
# Check if user modified the symlinked file (original vs new)
797+
if diff -q "$original_file" "$new_file" >/dev/null 2>&1; then
798+
# No difference - user didn't modify or changes are same as upstream
799+
return 0
800+
fi
801+
# User had changes that differ from upstream - conflict!
802+
return 1
803+
fi
804+
805+
# For regular files: check if user modified
793806
if ! is_config_modified "$config_name" "$user_file"; then
794807
# Not modified, safe to replace
795808
return 0
@@ -824,6 +837,11 @@ handle_config_conflict() {
824837
local config_name="$1"
825838
local user_file="$2"
826839
local new_file="$3"
840+
local original_file="$4" # User's version saved before git reset
841+
842+
# Use original_file for comparison (user_file may be symlink pointing to new version)
843+
local user_version="$original_file"
844+
[ ! -f "$user_version" ] && user_version="$user_file"
827845

828846
# Use loop instead of recursion to avoid stack depth issues
829847
while true; do
@@ -833,11 +851,11 @@ handle_config_conflict() {
833851
echo -e " ${YELLOW}╚═══════════════════════════════════════════════════════════╝${NC}"
834852
echo ""
835853

836-
# Show diff summary
837-
echo -e " ${CYAN}Changes summary:${NC}"
838-
diff --color=auto -u "$user_file" "$new_file" 2>/dev/null | head -30
854+
# Show diff summary (your version vs new version)
855+
echo -e " ${CYAN}Changes summary (your version → new version):${NC}"
856+
diff --color=auto -u "$user_version" "$new_file" 2>/dev/null | head -30
839857
local diff_lines
840-
diff_lines=$(diff -u "$user_file" "$new_file" 2>/dev/null | wc -l)
858+
diff_lines=$(diff -u "$user_version" "$new_file" 2>/dev/null | wc -l)
841859
if [ "$diff_lines" -gt 30 ]; then
842860
echo -e " ${YELLOW}... ($((diff_lines - 30)) more lines)${NC}"
843861
fi
@@ -854,26 +872,34 @@ handle_config_conflict() {
854872

855873
case "$choice" in
856874
1)
875+
# Restore user's version (convert symlink to regular file if needed)
876+
rm -f "$user_file" 2>/dev/null
877+
cp "$user_version" "$user_file"
857878
print_step " Keeping your version of $config_name"
858879
return 0
859880
;;
860881
2)
882+
rm -f "$user_file" 2>/dev/null
861883
cp "$new_file" "$user_file"
862884
print_success " Updated to new version: $config_name"
863885
return 0
864886
;;
865887
3)
866888
local backup_file="${user_file}.backup-$(date +%Y%m%d%H%M%S)"
867-
cp "$user_file" "$backup_file"
889+
cp "$user_version" "$backup_file"
890+
rm -f "$user_file" 2>/dev/null
868891
cp "$new_file" "$user_file"
869892
print_success " Updated $config_name (backup: $backup_file)"
870893
return 0
871894
;;
872895
4)
873-
diff --color=auto -u "$user_file" "$new_file" 2>/dev/null | less
896+
diff --color=auto -u "$user_version" "$new_file" 2>/dev/null | less
874897
# Loop continues to show menu again
875898
;;
876899
*)
900+
# Restore user's version
901+
rm -f "$user_file" 2>/dev/null
902+
cp "$user_version" "$user_file"
877903
print_step " Keeping your version of $config_name"
878904
return 0
879905
;;
@@ -1291,7 +1317,8 @@ do_draphyos_update() {
12911317
for config_name in "${conflicts[@]}"; do
12921318
local user_file="${config_map[$config_name]}"
12931319
local new_file="$INSTALL_DIR/configs/$config_name"
1294-
handle_config_conflict "$config_name" "$user_file" "$new_file"
1320+
local original_file="$original_configs_dir/$config_name"
1321+
handle_config_conflict "$config_name" "$user_file" "$new_file" "$original_file"
12951322
done
12961323
fi
12971324
echo ""

0 commit comments

Comments
 (0)