mirror of
https://github.com/ION606/VCS.git
synced 2026-05-14 22:16:55 +00:00
added base adding and removing
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
# helper function
|
||||
file_not_in_ogfiles() {
|
||||
local file="$1"
|
||||
for og_file in "${og_files[@]}"; do
|
||||
if [[ "$og_file" == "$file" ]]; then
|
||||
return 1 # File found
|
||||
fi
|
||||
done
|
||||
return 0 # File not found
|
||||
}
|
||||
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
echo -e "\e[31mERROR!\e[0m please specify what to $1, or use \e[34mionvcs $1 .\e[0m to select all"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
action="$1"
|
||||
regex="$2"
|
||||
|
||||
|
||||
# Check the .ionign file
|
||||
ignore_file="$PWD/.ionign"
|
||||
if [ -f "$ignore_file" ]; then
|
||||
# Read the .ionign file into an array
|
||||
mapfile -t ignore_patterns < "$ignore_file"
|
||||
else
|
||||
ignore_patterns=()
|
||||
fi
|
||||
|
||||
# Find all files that match the regex
|
||||
matching_files=$(find . -type f | grep -E "./${regex}")
|
||||
mapfile -t og_files < ".ionvcs/ogfiles.config"
|
||||
|
||||
|
||||
# Filter out ignored files
|
||||
filtered_files=$(echo "$matching_files" | while read -r file; do
|
||||
ignored=false
|
||||
for pattern in "${ignore_patterns[@]}"; do
|
||||
if [[ "$file" == *"$pattern"* ]]; then
|
||||
ignored=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
for pattern in "${og_files[@]}"; do
|
||||
if [[ "$file" == *"$pattern"* ]]; then
|
||||
ignored=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "$ignored" = false ]; then
|
||||
echo "$file"
|
||||
fi
|
||||
done)
|
||||
|
||||
if [ "$action" = "add" ]; then
|
||||
echo "Added:"
|
||||
for file in $filtered_files; do
|
||||
echo -e "\e[0;32m$file\e[0m"
|
||||
|
||||
if ! grep -qx "$file" ".ionvcs/add.config"; then
|
||||
echo "$file" >> ".ionvcs/add.config"
|
||||
elif file_not_in_ogfiles "$file"; then
|
||||
echo "$file" >> ".ionvcs/remove.config"
|
||||
fi
|
||||
done
|
||||
elif [ "$action" = "unstage" ]; then
|
||||
echo "Unstaged:"
|
||||
for file in $filtered_files; do
|
||||
echo -e "\e[0;31m$file\e[0m"
|
||||
|
||||
sed -i "\|^$file$|d" ".ionvcs/add.config"
|
||||
done
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
@@ -43,4 +43,5 @@ chmod 600 "$CONF_FILE"
|
||||
# Use rsync with sshpass to copy files with a progress bar
|
||||
echo -n "cloning..."
|
||||
/usr/bin/sshpass -p "$password" rsync -a --info=progress2 --no-i-r -h -e ssh "$REMOTE_PATH" "$DEST_FOLDER" || { echo "failed to clone!"; exit 1; }
|
||||
echo "$(find . -type f ! -wholename '.ionvcs/*')" > .ionvcs/ogfiles.config
|
||||
echo "done!"
|
||||
@@ -45,5 +45,5 @@ fi
|
||||
|
||||
# Use rsync with sshpass to copy files with a progress bar
|
||||
echo -n "cloning..."
|
||||
/usr/bin/sshpass -p "$password" rsync -avcn --exclude-from="$PWD/.ionign" --info=progress2 --no-i-r -h -e ssh "$DEST_FOLDER" "$REMOTE_PATH" || { echo "failed to clone!"; exit 1; }
|
||||
/usr/bin/sshpass -p "$password" rsync -avcn --include-from="$PWD/.ionvcs/add.config" --info=progress2 --no-i-r -h -e ssh "$DEST_FOLDER" "$REMOTE_PATH" || { echo "failed to clone!"; exit 1; }
|
||||
echo "done!"
|
||||
@@ -28,6 +28,14 @@ case $COMMAND in
|
||||
bash $HOME/ionsrc/help.sh
|
||||
;;
|
||||
|
||||
"unstage")
|
||||
bash $HOME/ionsrc/change.sh unstage "$@"
|
||||
;;
|
||||
|
||||
"add")
|
||||
bash $HOME/ionsrc/change.sh add "$@"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "UNKNOWN COMMAND \"$COMMAND\""
|
||||
GREEN='\033[0;31m'
|
||||
|
||||
@@ -24,13 +24,47 @@ else
|
||||
fi
|
||||
|
||||
# Use rsync with sshpass to check for differences without copying
|
||||
DIFF_OUTPUT=$(/usr/bin/sshpass -p "$password" rsync -avcn --delete -e ssh "$REMOTE_PATH" "$DEST_FOLDER")
|
||||
DIFF_OUTPUT=$(/usr/bin/sshpass -p "$password" rsync -avcn --delete -e ssh "$REMOTE_PATH" "$DEST_FOLDER") || echo "FAILED TO CONNECT TO SOURCE!"
|
||||
|
||||
# Check if there are differences
|
||||
if [ ! -z "$DIFF_OUTPUT" ]; then
|
||||
echo -e "\e[1;32mdifferences found\e[0m"
|
||||
echo "$DIFF_OUTPUT"
|
||||
exit 1;
|
||||
else
|
||||
echo "no changes found!"
|
||||
fi
|
||||
echo "no changes found from remote"
|
||||
fi
|
||||
|
||||
# Files
|
||||
ogfiles=".ionvcs/ogfiles.config"
|
||||
addfiles=".ionvcs/add.config"
|
||||
|
||||
# Check if the necessary files exist
|
||||
if [ ! -f "$ogfiles" ]; then
|
||||
echo "The file $ogfiles does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$addfiles" ]; then
|
||||
echo "The file $addfiles does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read the .ionvcs/add.config into an array
|
||||
mapfile -t add_files < "$addfiles"
|
||||
mapfile -t all_files < "$ogfiles"
|
||||
|
||||
|
||||
# Read the .ionvcs/ogfiles.config and process each line
|
||||
while IFS= read -r file; do
|
||||
if [ ! -f "$file" ]; then
|
||||
# File is not in the current directory
|
||||
echo -e "\e[0;31m$file\e[0m"
|
||||
fi
|
||||
done < "$ogfiles"
|
||||
|
||||
while IFS= read -r file; do
|
||||
if ! (printf '%s\n' "${all_files[@]}" | grep -qx "$file"); then
|
||||
# File is in .ionvcs/add.config
|
||||
echo -e "\e[0;32m$file\e[0m"
|
||||
fi
|
||||
done < "$addfiles"
|
||||
Reference in New Issue
Block a user