dolthub / dolthub/dolt

Incorrect behavior when attempting to rename active branches with `dolt_branch` stored procedure.

Open
#6,100 0 comments 0 reactions 2 assignees Claimed by @zachmu View on GitHub
bug sql version control
Dominant language
Go
Stars
24.4k
Forks
873
Avg merge
1d 5h
Merged PRs (30d)
108

Description

There are three possibly related issues, depending on whether the user is connecting to a server or a local db, and whether the active branch is "session active branch" within the SQL session or the "default active branch" set by the db. I'm grouping them here because decisions about the desired behavior will affect all three.

## Bug 1: Renaming the session active branch on a local db results in action to be only partially successful.

To reproduce:
```
dolt init
dolt branch other
echo "call dolt_checkout('other'); call dolt_branch('-m', 'other', 'newOther')" | dolt sql
dolt branch
```

expected output:
```
newOther
other
```

actual output:

`dolt sql` call fails with `Cannot set cwb head ref with a SessionStateAdapter`
```
main
newOther
other
```

The new branch name has been created but the old name still exists.

## Bug 2: Renaming the session active branch on a remote db results in misleading error message.

To reproduce:
```
mkdir repo
cd repo
dolt init
dolt branch other
dolt sql-server
echo "use repo;\\n call dolt_checkout('other');\\n call dolt_branch('-m', 'other', 'newOther')" | dolt sql-client -u root
dolt branch
```

Error:

```
Error 1105: unsafe to delete or rename branches in use in other sessions; use --force to force the change
```

The branch isn't in use in other sessions, but it *is* in use in this session. Calling `dolt_branch` with `--force` results in the same behavior as Bug 1.

I don't know if we actually want to forbid this rename or not, but if so we might want to improve the error message.

## Bug 3: Renaming the default active branch on a remote db succeeds, but does not update the head in `repo_state.json`

To reproduce:

```
mkdir repo
cd repo
dolt init
dolt branch other
dolt sql-server
echo "use repo;\\n call dolt_checkout('other');\\n call dolt_branch('-m', 'main', 'newMain')" | dolt sql-client -u root
dolt branch
```

Output:

```
error: failed to read local branches from db
cause: Error 1105: branch not found
```

Furthermore:

```
echo "use dbname;" | dolt sql-client -u root
```

results in

```
Error 1105: branch not found
```

A user can escape this by running `dolt branch `, but this requires them to know the name of an existing branch, and they can't use `dolt branch` to find one.

This happens because `repo_state.json` was never updated and continues to point to the now nonexistent branch name.

I'm not sure if we want to allow or forbid renaming the default active branch while a server is running. But this shouldn't happen.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.