Staubgeborener / Klipper-Backup

Klipper-Backup is a script for manual or automated Klipper GitHub backups. It's Lightweight, pragmatic and comfortable.
https://klipperbackup.xyz
300 stars 58 forks source link

Add git url as parameter #55

Closed TheZoker closed 9 months ago

TheZoker commented 9 months ago

A sample integration of the git URL parameter

Closes #54

Staubgeborener commented 9 months ago

I have the same opinion as @Tylerjet. Could you please change your PR (remove the line in .env file and adjust the corresponding lines in script.sh). After that we can merge that and change the docs for this optional parameter.

TheZoker commented 9 months ago

I implemented your suggestions :) Thanks for the review!

Staubgeborener commented 9 months ago

I started a review, please check this.

Also, we implemented some if-statements (like this or this) in order to update the .git folder inside the config_backup folder and by doing so be more flexible. Otherwise, the user will get an error in the following example scenario:

  1. add git_url=some-url.com in .env
  2. run ./script.sh in order to push files
  3. edit git_url=some-other-url.com in .env
  4. run ./script.sh again in order to push files

In this case, git still tries to push the files to some-url.com as the URL is not updated by itself. The if-statements check if the corresponding line inside the .env file does not match with the information inside the ~/config_backup/.git folder. So we need something like

if [[ "$git_url" != $(git remote get-url origin | sed command to grep the some-url.com url) ]];

TheZoker commented 9 months ago

Can't we just set the URL on every run like this?

git remote set-url origin $git_url

That way we don't have to check if the URL is different, we just always use the current set URL

Tylerjet commented 9 months ago

ah that works as well hehe

TheZoker commented 9 months ago

I pushed you changes 👍

Tylerjet commented 9 months ago

@TheZoker one last thing actually is the final lines from line ~61 - 64

# Check if remote origin changed and update when it is
if [[ "$github_repository" != $(git remote get-url origin | sed 's/https:\/\/.*@github.com\///' | sed 's/\.git$//' | xargs basename) ]]; then
    git remote set-url origin https://"$github_token"@"$git_url"/"$github_username"/"$github_repository".git
if [[ "$full_git_url" != $(git remote get-url origin) ]]; then
    git remote set-url origin "$full_git_url"
fi
fi

it should be

# Check if remote origin changed and update when it is
if [[ "$full_git_url" != $(git remote get-url origin) ]]; then
    git remote set-url origin "$full_git_url"
fi

for some reason my suggestion didn't substitute the right section

Tylerjet commented 9 months ago

Perfect!

TheZoker commented 9 months ago

I just saw that and was already fixing it, but this way it was faster :D

Tylerjet commented 9 months ago

@Staubgeborener should be good to merge now!

Staubgeborener commented 9 months ago

Nice work!