Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oxidize comtrya #1321

Open
1 of 4 tasks
Byron opened this issue Mar 16, 2024 · 4 comments
Open
1 of 4 tasks

Oxidize comtrya #1321

Byron opened this issue Mar 16, 2024 · 4 comments
Labels
C-integrate-gitoxide "Oxidize" crates even more by replacing git2 with gitoxide

Comments

@Byron
Copy link
Member

Byron commented Mar 16, 2024

Required Features

  • fetch
  • rebase
  • merge
  • worktree reset
  • …more analysis TBD

See the sibling issue in comtrya/comtrya#347

@Byron Byron added the C-integrate-gitoxide "Oxidize" crates even more by replacing git2 with gitoxide label Mar 16, 2024
@Byron Byron mentioned this issue Mar 16, 2024
@rawkode
Copy link

rawkode commented Apr 2, 2024

Scratch that, let me try and implement this again and see what happens.

@rawkode
Copy link

rawkode commented Apr 2, 2024

Hi @Byron,

I've updated GitSync to (which Comtrya uses) to use this for clone_repository()

    fn clone_repository(&self) -> Result<(), errors::GitSyncError> {
        info!("Attempting to clone {} to {:?}", self.repo, self.dir,);

        unsafe {
            match gix::interrupt::init_handler(1, || {}) {
                Ok(_) => (),
                Err(error) => {
                    return Err(GitSyncError::GenericError { error });
                }
            };
        }

        if !self.dir.exists() {
            match std::fs::create_dir_all(&self.dir) {
                Ok(_) => {}
                Err(error) => {
                    return Err(GitSyncError::GenericError { error });
                }
            }
        }

        let url = match gix::url::parse(self.repo.as_str().into()) {
            Ok(url) => url,
            Err(error) => {
                return Err(GitSyncError::GixParseError { error });
            }
        };

        let mut prepare_clone = match gix::prepare_clone(url, &self.dir) {
            Ok(prepared_fetch) => prepared_fetch,
            Err(error) => {
                return Err(GitSyncError::GixCloneError { error });
            }
        };

        let (mut prepare_checkout, _) = match prepare_clone
            .fetch_then_checkout(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)
        {
            Ok(checkout) => checkout,
            Err(error) => {
                return Err(GitSyncError::GixCloneFetchError { error });
            }
        };

        match prepare_checkout
            .main_worktree(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)
        {
            Ok(repository) => repository,
            Err(error) => {
                return Err(GitSyncError::GixCloneCheckoutError { error });
            }
        };

        Ok(())
    }

and this works well.

We also have a sync function, which is using gix::open(); but I can't work out how to fetch_then_checkout on an existing repository.

I've also tried just using clone_repository with the dir being the existing checkout, but it doesn't seem like HEAD is updated.

Any advice?

@rawkode
Copy link

rawkode commented Apr 2, 2024

Draft PR

rawkode/gitsync#4

@Byron
Copy link
Member Author

Byron commented Apr 2, 2024

Thanks for trying it out!

and this works well.

Is the question-mark operation ? forbidden in your codebase? I am pretty sure clippy would take offence in not using it -error-handling seems unnecessarily verbose. Since it's an application, I'd recommend anyhow as well.

We also have a sync function, which is using gix::open(); but I can't work out how to fetch_then_checkout on an existing repository.

One cannot yet checkout into an existing repository, and I'd hope it refuses to do so into an existing non-empty directory as it would bluntly overwrite everything. It's only possible to checkout the initial clone.

It will take a while until git reset/checkout are possible, but this PR and it's follow-ups will lead there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-integrate-gitoxide "Oxidize" crates even more by replacing git2 with gitoxide
Projects
None yet
Development

No branches or pull requests

2 participants