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

Main branch deleted after git sync #476

Closed
mikepqr opened this issue Jul 28, 2022 · 6 comments · Fixed by #593
Closed

Main branch deleted after git sync #476

mikepqr opened this issue Jul 28, 2022 · 6 comments · Fixed by #593
Labels
bug Something isn't working

Comments

@mikepqr
Copy link

mikepqr commented Jul 28, 2022

Description of the bug

I get an error (warning?) that the main branch could not be found every time I git sync after landing a change. I'm left on a detached HEAD (possibly this is expected?) and git sl fails (definitely not expected!). If I then explicitly checkout master I get back to a working state.

Expected behavior

git sync and git sl work without an error.

Actual behavior

$ git fetch
origin: Extents updated: 1283 transactions
origin: Updating from https://git.twitter.biz/source/objects/journals/32.bin
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  307k  100  307k    0     0   739k      0 --:--:-- --:--:-- --:--:--  739k
Replaying transactions: 100% (1283/1283), done.
cannot delete non-empty directory: reference-transaction.d

$ git branch
* master

$ git sync
Attempting rebase in-memory...
[1/1] Skipped commit (was already applied upstream): a618c8d3 TNB. Move overnight build to early morning
branchless: processing 1 rewritten commit
The application panicked (crashed).
Message:  A fatal error occurred:
   0: Could not find repository main branch
Location:
   /Users/mleewilliams/.cargo/registry/src/github.com-1ecc6299db9ec823/git-branchless-lib-0.3.12/src/git/repo.rs:404
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   0: branchless::git::repo::get_main_branch_oid with self=<Git repository at: "/Users/mleewilliams/workspace/source/.git/">
      at /Users/mleewilliams/.cargo/registry/src/github.com-1ecc6299db9ec823/git-branchless-lib-0.3.12/src/git/repo.rs:412
   1: branchless::core::rewrite::rewrite_hooks::warn_abandoned with effects=<Output fancy=false> repo=<Git repository at: "/Users/mleewilliams/workspace/source/.git/"> conn=Connection { path: Some("/Users/mleewilliams/workspace/source/.git/branchless/db.sqlite3") } event_log_db=<EventLogDb>
      at /Users/mleewilliams/.cargo/registry/src/github.com-1ecc6299db9ec823/git-branchless-lib-0.3.12/src/core/rewrite/rewrite_hooks.rs:193
   2: branchless::core::rewrite::rewrite_hooks::hook_post_rewrite with effects=<Output fancy=false> git_run_info=<GitRunInfo path_to_git="git" working_directory="/Users/mleewilliams/workspace/source" env=not shown> rewrite_type="rebase"
      at /Users/mleewilliams/.cargo/registry/src/github.com-1ecc6299db9ec823/git-branchless-lib-0.3.12/src/core/rewrite/rewrite_hooks.rs:105
Suggestion:
The main branch "master" could not be found in your repository
at path: "/Users/mleewilliams/workspace/source/.git/".
These branches exist: []
Either create it, or update the main branch setting by running:
    git config branchless.core.mainBranch <branch>
Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
Location: /Users/mleewilliams/.cargo/registry/src/github.com-1ecc6299db9ec823/git-branchless-0.3.12/src/commands/mod.rs:298
Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
branchless: running command: git checkout 10cacf4f994e837bf97e25f9d99760f9c2be49e9
⠖ Syncing commit stacks (5.0s)                                                                                       ░░░░░░░░░░░░░░░░░░░░ 0/1
Previous HEAD position was a618c8d3e49a4 TNB. Move overnight build to early morning
HEAD is now at 10cacf4f994e8 Docbird: Edit 12086 applied automatically from browser, without review. AUTOMATED_COMMIT=true
branchless: processing checkout
In-memory rebase succeeded.
Synced a618c8d3 TNB. Move overnight build to early morning
(HEAD detached at 10cacf4f994e8)

$ git sl
The application panicked (crashed).
Message:  A fatal error occurred:
   0: Could not find repository main branch
Location:
   /Users/mleewilliams/.cargo/registry/src/github.com-1ecc6299db9ec823/git-branchless-lib-0.3.12/src/git/repo.rs:404
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   0: branchless::git::repo::get_main_branch_oid with self=<Git repository at: "/Users/mleewilliams/workspace/source/.git/">
      at /Users/mleewilliams/.cargo/registry/src/github.com-1ecc6299db9ec823/git-branchless-lib-0.3.12/src/git/repo.rs:412
   1: git_branchless::commands::smartlog::smartlog with effects=<Output fancy=true> git_run_info=<GitRunInfo path_to_git="git" working_directory="/Users/mleewilliams/workspace/source" env=not shown> options=SmartlogOptions { show_hidden_commits: false, only_show_branches: false }
      at /Users/mleewilliams/.cargo/registry/src/github.com-1ecc6299db9ec823/git-branchless-0.3.12/src/commands/smartlog.rs:533
Suggestion:
The main branch "master" could not be found in your repository
at path: "/Users/mleewilliams/workspace/source/.git/".
These branches exist: []
Either create it, or update the main branch setting by running:
    git config branchless.core.mainBranch <branch>
Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
Location: /Users/mleewilliams/.cargo/registry/src/github.com-1ecc6299db9ec823/git-branchless-0.3.12/src/commands/mod.rs:298
Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
(HEAD detached at 10cacf4f994e8)

$ git checkout master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to a new branch 'master'
Your branch is up to date with 'origin/master'.
branchless: processing checkout

$ git sl
⋮
◆ 10cacf4 2m (remote origin/master, ᐅ master) Docbird: Edit 12086 applied automatically from browser, without review. AUTOMATED_COMMIT=true

Version of rustc

rustc 1.59.0

Automated bug report

#### Software version

git-branchless 0.3.12

#### Operating system

macOS 12.5 (Darwin 21.6.0)

#### Command-line

```bash
/Users/mleewilliams/.cargo/bin/git-branchless bug-report 

Environment variables

SHELL=/bin/bash
EDITOR=nvim

Git version

> git version 
git version 2.25.0.853.g5575ef6-twtrsrc

Events

Show 5 events
Event ID: 451, transaction ID: 475
  1. RefUpdateEvent { timestamp: 1658965620.970999, event_tx_id: EventTransactionId(475), ref_name: "HEAD", old_oid: 10cacf4f994e837bf97e25f9d99760f9c2be49e9, new_oid: 10cacf4f994e837bf97e25f9d99760f9c2be49e9, message: None }
:
@ 10cacf4 24m (redacted-ref-0) xxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxxxxx xxxx xxxxxxxx xxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxx
:
O 3d197ce 3m (remote origin/master) xxxxxxxxxxxxxxxxxx xxx xxxx xxxxx xxxxxxxx
Event ID: 449, transaction ID: 474
  1. RewriteEvent { timestamp: 1658965570.51185, event_tx_id: EventTransactionId(474), old_commit_oid: a618c8d3e49a48df84c072281958c4059ce820d6, new_commit_oid: 0000000000000000000000000000000000000000 }
  2. RefUpdateEvent { timestamp: 1658965596.124385, event_tx_id: EventTransactionId(474), ref_name: "HEAD", old_oid: a618c8d3e49a48df84c072281958c4059ce820d6, new_oid: 10cacf4f994e837bf97e25f9d99760f9c2be49e9, message: None }
:
@ 10cacf4 24m (redacted-ref-0) xxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxxxxx xxxx xxxxxxxx xxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxx
:
O 3d197ce 3m (remote origin/master) xxxxxxxxxxxxxxxxxx xxx xxxx xxxxx xxxxxxxx
Event ID: 448, transaction ID: 472
  1. RewriteEvent { timestamp: 1658944229.534632, event_tx_id: EventTransactionId(472), old_commit_oid: 2b250d3c4fd0fcf156cc8eaf5f4b95814c9fcc22, new_commit_oid: a618c8d3e49a48df84c072281958c4059ce820d6 }
:
@ 10cacf4 24m (redacted-ref-0) xxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxxxxx xxxx xxxxxxxx xxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxx
:
O 3d197ce 3m (remote origin/master) xxxxxxxxxxxxxxxxxx xxx xxxx xxxxx xxxxxxxx
Event ID: 447, transaction ID: 471
  1. CommitEvent { timestamp: 1658944228.0, event_tx_id: EventTransactionId(471), commit_oid: NonZeroOid(a618c8d3e49a48df84c072281958c4059ce820d6) }
:
@ 10cacf4 24m (redacted-ref-0) xxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxxxxx xxxx xxxxxxxx xxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxx
:
O 3d197ce 3m (remote origin/master) xxxxxxxxxxxxxxxxxx xxx xxxx xxxxx xxxxxxxx
Event ID: 446, transaction ID: 470
  1. CommitEvent { timestamp: 1658943942.0, event_tx_id: EventTransactionId(470), commit_oid: NonZeroOid(2b250d3c4fd0fcf156cc8eaf5f4b95814c9fcc22) }
:
@ 10cacf4 24m (redacted-ref-0) xxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxxxxx xxxx xxxxxxxx xxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxx
:
O 3d197ce 3m (remote origin/master) xxxxxxxxxxxxxxxxxx xxx xxxx xxxxx xxxxxxxx
```

Version of git-branchless

No response

Version of git

No response

@mikepqr mikepqr added the bug Something isn't working label Jul 28, 2022
@arxanas
Copy link
Owner

arxanas commented Aug 2, 2022

Hi @mikepqr, thanks for reporting! I was able to reproduce the issue and put up a fix in #485. Can you test it out (instructions) and confirm that it resolves the bug?

@mikepqr
Copy link
Author

mikepqr commented Aug 2, 2022

Awesome! Happy to test but I'm afraid I need a little basic cargo support to unblock:

$ cargo install --locked --git https://github.com/arxanas/git-branchless --branch arxanas/sync git-branchless --force
    Updating git repository `https://github.com/arxanas/git-branchless`
  Installing git-branchless v0.3.12 (https://github.com/arxanas/git-branchless?branch=arxanas/sync#e3ccc646)
    Updating crates.io index
error: failed to select a version for the requirement `libgit2-sys = "^0.14.0"`
candidate versions found which didn't match: 0.13.2+1.4.2, 0.13.1+1.4.2, 0.13.0+1.4.1, ...
location searched: crates.io index
required by package `git2 v0.15.0`
    ... which satisfies dependency `git2 = "^0.15.0"` (locked to 0.15.0) of package `git-branchless-lib v0.3.12 (/Users/mleewilliams/.cargo/git/checkouts/git-branchless-f6bbbe393421e02f/e3ccc64/git-branchless-lib)`
    ... which satisfies path dependency `lib` (locked to 0.3.12) of package `git-branchless v0.3.12 (/Users/mleewilliams/.cargo/git/checkouts/git-branchless-f6bbbe393421e02f/e3ccc64/git-branchless)`

@arxanas
Copy link
Owner

arxanas commented Aug 4, 2022

@mikepqr sorry about that, the error message is quite bad here. You need to update your version of Rust/Cargo. cargo in an older version can't resolve these dependencies properly, which produces this error message. git-branchless is marked as requiring Rust 1.61.0 or later, but cargo tries to resolve dependencies before it can check for this. I'll add a note to this Troubleshooting section too.

@arxanas
Copy link
Owner

arxanas commented Aug 4, 2022

By the way, as a workaround, you can try committing to branches other than master, or try not committing to master at all and using a branchless strategy (i.e. run git checkout --detach before committing). This seems to be happening when you make changes to master and then apply them upstream and run git sync.

@mikepqr
Copy link
Author

mikepqr commented Aug 10, 2022

Thanks! I've upgraded to #485 and will let you know how I get on.

@arxanas arxanas changed the title "Main branch "master" could not be found in your repository" but it's right there! Main branch deleted after git sync Oct 2, 2022
@arxanas
Copy link
Owner

arxanas commented Oct 14, 2022

Closed in #593.

@arxanas arxanas closed this as completed Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants