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

Error: UnbornBranch #128

Open
tkellogg opened this issue Nov 28, 2022 · 6 comments
Open

Error: UnbornBranch #128

tkellogg opened this issue Nov 28, 2022 · 6 comments
Labels
bug Something isn't working good first issue Good for newcomers rust Pull requests that update Rust code

Comments

@tkellogg
Copy link
Owner

Repro

  • Run dura serve
  • Create a new repo, e.g. with cargo new, and make changes without committing
  • Check the stdout log, there should be errors that look like:
{"target":"dura::poller","file":"src/poller.rs","name":"event src/poller.rs:41","level":"Level(Info)","fields":{"message":"info_operation","operation":{"Snapshot":{"error":"reference 'refs/heads/master' not found; class=Reference (4); code=UnbornBranch (-9)","latency":0.000267355,"op":null,"repo":"/Users/timkellogg/code/oss/syndr"}}},"time":"2022-11-28T14:27:18.611085+00:00"}

Expected behavior

This happens when there's no first commit. Normally the branch name is dura_{base_commit_hash}, in this case we could make it a constant dura_unborn or dura_init.

This also means that the first commit in sequence might not have a parent, which may cause other problems.

@tkellogg tkellogg added bug Something isn't working good first issue Good for newcomers rust Pull requests that update Rust code labels Nov 28, 2022
@Amanse
Copy link
Contributor

Amanse commented Nov 29, 2022

I am not as familiar with the code base, but as far as i understand, changing in src/snapshots.rs for branch name to be something else should work, but how would you want the parent commit handled? it could be made into an Option<> or maybe error handled when it is needed some other way

@tkellogg
Copy link
Owner Author

Ah! Git trivia time! The parent commit is a plain list of commit hashes.

  • 0 commits = first commit
  • 1 commit = the normal case
  • 2 commits = merge commit
  • 3+ commits = octopus merge

So yeah, it's as simple as giving it an empty slice.

@Amanse
Copy link
Contributor

Amanse commented Nov 29, 2022

love your style haha
i will try this tomorrow(in about ~12 hours)
have really taken a liking to this project 😄

@Amanse
Copy link
Contributor

Amanse commented Nov 30, 2022

If dura makes the first commit would that set the dura_unborn as the default branch?
also i am thinking something like this to error handle the head, but it doesn't seem elegant

let head = match repo.head() {
        Ok(v) => peel_to_commit(v)?,
        Err(e) => if e.code() == git2::UnbornBranch {
            // handle unborn branch
        } else {
            return Err(e);
        }
    }
}

@tkellogg
Copy link
Owner Author

I don't know. Write a test and find out!

@Amanse
Copy link
Contributor

Amanse commented Nov 30, 2022

I went the way of making head: Option<git2::Commit> which seemed logical as it can None when there is no head
but this has an adverse effect that all the statements in the capture function need to be if let Some(h) = head and it then extends to parent_commit being an option because git2 doesn't support empty slice as a parent, and the if let Some hell extends to it too.

I am thinking that once we check if head exists or not, it can be divided into 2 capture functions. Once dura makes the commit in the unborn_capture function it will have a head to use and will no longer fall back on that function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers rust Pull requests that update Rust code
Projects
None yet
Development

No branches or pull requests

2 participants