add --git sync option

This commit is contained in:
2026-01-23 17:37:04 +02:00
parent ce339d383c
commit a3598a5f79
3 changed files with 88 additions and 2 deletions

16
MANUAL
View File

@@ -29,6 +29,12 @@ OPTIONS
Setup mode for SFTP workflow. Creates helper scripts but skips
lazygit upload and .gitignore modifications.
--git
Git clone mode. Clones the repository from the remote server using
SSH with password authentication. Uploads lazygit to the server and
marks it as assume-unchanged (both locally and on server). Only
generates ssh.sh helper script.
MODES
Default mode:
- Syncs terminal info (xterm-ghostty or xterm-kitty)
@@ -49,6 +55,13 @@ MODES
- No helper scripts
- No configuration files
--git mode:
- Clones git repository via SSH with password
- Uploads lazygit to server
- Marks lazygit as assume-unchanged (server + local)
- Generates: ssh.sh only
- No tar archive, no sftp.json, no other scripts
EXAMPLES
Full setup with all scripts:
./sync-project.sh
@@ -59,6 +72,9 @@ EXAMPLES
SFTP workflow without git tools:
./sync-project.sh --sftp-only
Clone git repository from server:
./sync-project.sh --git
GENERATED SCRIPTS
remote-local.sh Pull files from server
local-remote.sh Push files to server

View File

@@ -24,8 +24,10 @@ elif [ "$1" = "--git" ]; then
ssh -t $SERVER_USER@$SERVER_HOST \
"cd $SERVER_PATH && ./lazygit"
# After that sync remote with --delete flag
bash remote-local.sh --delete
# After that sync remote with --delete flag (if script exists)
if [ -f "remote-local.sh" ]; then
bash remote-local.sh --delete
fi
elif [ "$1" = "--todo" ]; then
todoSearch
else

View File

@@ -21,6 +21,7 @@ SSH_OPTS="-o StrictHostKeyChecking=accept-new"
# Parse command line arguments
SFTP_ONLY=false
FILES_ONLY=false
GIT_ONLY=false
for arg in "$@"; do
case "$arg" in
@@ -36,6 +37,10 @@ for arg in "$@"; do
FILES_ONLY=true
echo -e "${YELLOW}Files only mode enabled${NC}"
;;
--git)
GIT_ONLY=true
echo -e "${YELLOW}Git clone mode enabled${NC}"
;;
esac
done
@@ -99,6 +104,69 @@ if [ -z "$LOCAL_FOLDER" ]; then
exit 1
fi
# Git clone mode - clone repository and setup lazygit
if [ "$GIT_ONLY" = true ]; then
echo "Cloning repository..."
GIT_SSH_COMMAND="sshpass -p '${SSH_PASSWORD}' ssh $SSH_OPTS" \
git clone ${SERVER_HOST}:${SERVER_PROJECT_PATH} "${LOCAL_FOLDER}"
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to clone repository${NC}"
exit 1
fi
echo -e "${GREEN}Repository cloned successfully${NC}"
# Extract username and host from SERVER_HOST
USERNAME="${SERVER_HOST%@*}"
HOST="${SERVER_HOST#*@}"
cd "${LOCAL_FOLDER}"
# Upload lazygit to server
echo "Uploading lazygit to server..."
sshpass -p "${SSH_PASSWORD}" scp $SSH_OPTS "${SCRIPT_DIR}/lazygit" ${SERVER_HOST}:${SERVER_PROJECT_PATH}
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to upload lazygit${NC}"
exit 1
fi
echo -e "${GREEN}lazygit uploaded successfully${NC}"
# Mark lazygit as assume-unchanged on server
echo "Marking lazygit as assume-unchanged on server..."
sshpass -p "${SSH_PASSWORD}" ssh $SSH_OPTS ${SERVER_HOST} \
"cd ${SERVER_PROJECT_PATH} && git update-index --assume-unchanged lazygit"
# Pull to get lazygit locally, then mark as assume-unchanged
echo "Syncing and marking lazygit as assume-unchanged locally..."
GIT_SSH_COMMAND="sshpass -p '${SSH_PASSWORD}' ssh $SSH_OPTS" git pull
git update-index --assume-unchanged lazygit
echo -e "${GREEN}lazygit configured successfully${NC}"
# Generate ssh.sh script
echo "
#!/bin/bash
set -e
# Configuration
SERVER_USER=\"${USERNAME}\"
SERVER_HOST=\"${HOST}\"
SERVER_PASSWORD=\"${SSH_PASSWORD}\"
SERVER_PATH=\"${SERVER_PROJECT_PATH}/\"
REMOTE_PROGRESS=\".remote-in-progress\"
" > "ssh.sh"
# Append the ssh.sh template
cat "${SCRIPT_DIR}/scripts/ssh.sh" >> "ssh.sh"
echo -e "${GREEN}ssh.sh created successfully${NC}"
echo -e "${GREEN}Git clone complete!${NC}"
exit 0
fi
# Sync terminal info on full sync (no flags)
if [ "$SFTP_ONLY" = false ] && [ "$FILES_ONLY" = false ]; then
# Detect terminal type