pub fn check_update() -> Result<APIResponseTips> {

        let remote_tips_path = get_remote_tips_path()?;
        let mut repo = match Repository::open(&remote_tips_path) {
            Ok(repo) => repo,

            // If this fails, it means we either we don´t have the tips downloaded, or we have a folder without the .git folder.
            Err(_) => return Ok(APIResponseTips::NoLocalFiles),
        };

        // Just in case there are loose changes, stash them.
        // Ignore a fail on this, as it's possible we don't have contents to stash.
        let current_branch_name = Reference::normalize_name(repo.head()?.name().unwrap(), ReferenceFormat::ALLOW_ONELEVEL)?.to_lowercase();
        let master_refname = format!("refs/heads/{}", MASTER);

        let signature = Signature::now("RPFM Updater", "-")?;
        let stash_id = repo.stash_save(&signature, &format!("Stashed changes before checking for updates from branch {}", current_branch_name), Some(StashFlags::INCLUDE_UNTRACKED));

        // In case we're not in master, checkout the master branch.
        if current_branch_name != master_refname {
            repo.set_head(&master_refname)?;
        }

        // Fetch the info of the master branch.
        repo.find_remote(REMOTE)?.fetch(&[MASTER], None, None)?;
        let analysis = {
            let fetch_head = repo.find_reference("FETCH_HEAD")?;
            let fetch_commit = repo.reference_to_annotated_commit(&fetch_head)?;
            repo.merge_analysis(&[&fetch_commit])?
        };

        // Reset the repo to his original state after the check
        if current_branch_name != master_refname {
            let _ = repo.set_head(&current_branch_name);
        }
        if stash_id.is_ok() {
            let _ = repo.stash_pop(0, None);
        }

        if analysis.0.is_up_to_date() {
            Ok(APIResponseTips::NoUpdate)
        }

        // If the branch is a fast-forward, or has diverged, ask for an update.
        else if analysis.0.is_fast_forward() || analysis.0.is_normal() || analysis.0.is_none() || analysis.0.is_unborn() {
            Ok(APIResponseTips::NewUpdate)
        }

        // Otherwise, it means the branches diverged. This may be due to local changes or due to me diverging the master branch with a force push.
        else {
            Err(ErrorKind::MessagesUpdateError.into())
        }
    }
/// This function checks if there is a new tips update in the tips repo.
This function checks if there is a new tips update in the tips repo.
This function checks if there is a new tips update in the tips repo .
pub fn check_update() -> Result<APIResponseTips> {
        let remote_tips_path = get_remote_tips_path()?;
        let mut repo = match Repository::open(&remote_tips_path) {
            Ok(repo) => repo,
            // If this fails, it means we either we don´t have the tips downloaded, or we have a folder without the .git folder.
            Err(_) => return Ok(APIResponseTips::NoLocalFiles),
        };
        // Just in case there are loose changes, stash them.
        // Ignore a fail on this, as it's possible we don't have contents to stash.
        let current_branch_name = Reference::normalize_name(repo.head()?.name().unwrap(), ReferenceFormat::ALLOW_ONELEVEL)?.to_lowercase();
        let master_refname = format!("refs/heads/{}", MASTER);
        let signature = Signature::now("RPFM Updater", "-")?;
        let stash_id = repo.stash_save(&signature, &format!("Stashed changes before checking for updates from branch {}", current_branch_name), Some(StashFlags::INCLUDE_UNTRACKED));
        // In case we're not in master, checkout the master branch.
        if current_branch_name != master_refname {
            repo.set_head(&master_refname)?;
        }
        // Fetch the info of the master branch.
        repo.find_remote(REMOTE)?.fetch(&[MASTER], None, None)?;
        let analysis = {
            let fetch_head = repo.find_reference("FETCH_HEAD")?;
            let fetch_commit = repo.reference_to_annotated_commit(&fetch_head)?;
            repo.merge_analysis(&[&fetch_commit])?
        };
        // Reset the repo to his original state after the check
        if current_branch_name != master_refname {
            let _ = repo.set_head(&current_branch_name);
        }
        if stash_id.is_ok() {
            let _ = repo.stash_pop(0, None);
        }
        if analysis.0.is_up_to_date() {
            Ok(APIResponseTips::NoUpdate)
        }
        // If the branch is a fast-forward, or has diverged, ask for an update.
        else if analysis.0.is_fast_forward() || analysis.0.is_normal() || analysis.0.is_none() || analysis.0.is_unborn() {
            Ok(APIResponseTips::NewUpdate)
        }
        // Otherwise, it means the branches diverged. This may be due to local changes or due to me diverging the master branch with a force push.
        else {
            Err(ErrorKind::MessagesUpdateError.into())
        }
    }
pub fn check_update ( ) -> Result < APIResponseTips > { let remote_tips_path = get_remote_tips_path ( ) ? ; let mut repo = match Repository :: open ( & remote_tips_path ) { Ok ( repo ) => repo , // If this fails, it means we either we don´t have the tips downloaded, or we have a folder without the .git folder. Err ( _ ) => return Ok ( APIResponseTips :: NoLocalFiles ) , } ; // Just in case there are loose changes, stash them. // Ignore a fail on this, as it's possible we don't have contents to stash. let current_branch_name = Reference :: normalize_name ( repo . head ( ) ? . name ( ) . unwrap ( ) , ReferenceFormat :: ALLOW_ONELEVEL ) ? . to_lowercase ( ) ; let master_refname = format ! ( " " MASTER ) ; let signature = Signature :: now ( " " , " " ) ? ; let stash_id = repo . stash_save ( & signature , & format ! ( " " current_branch_name ) , Some ( StashFlags :: INCLUDE_UNTRACKED ) ) ; // In case we're not in master, checkout the master branch. if current_branch_name != master_refname { repo . set_head ( & master_refname ) ? ; } // Fetch the info of the master branch. repo . find_remote ( REMOTE ) ? . fetch ( & [ MASTER ] , None , None ) ? ; let analysis = { let fetch_head = repo . find_reference ( " " ) ? ; let fetch_commit = repo . reference_to_annotated_commit ( & fetch_head ) ? ; repo . merge_analysis ( & [ & fetch_commit ] ) ? } ; // Reset the repo to his original state after the check if current_branch_name != master_refname { let _ = repo . set_head ( & current_branch_name ) ; } if stash_id . is_ok ( ) { let _ = repo . stash_pop ( 0 , None ) ; } if analysis . 0 . is_up_to_date ( ) { Ok ( APIResponseTips :: NoUpdate ) } // If the branch is a fast-forward, or has diverged, ask for an update. else if analysis . 0 . is_fast_forward ( ) || analysis . 0 . is_normal ( ) || analysis . 0 . is_none ( ) || analysis . 0 . is_unborn ( ) { Ok ( APIResponseTips :: NewUpdate ) } // Otherwise, it means the branches diverged. This may be due to local changes or due to me diverging the master branch with a force push. else { Err ( ErrorKind :: MessagesUpdateError . into ( ) ) } }
This function checks if there is a new tips update in the tips repo.
This function checks if there is a new tips update in the tips repo .