go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
43.34k stars 5.34k forks source link

Web interface reports incorrect statistics #21781

Open Gregory92 opened 1 year ago

Gregory92 commented 1 year ago

Description

In Gitea, I have deleted a branch named "note-new" after I didn't like the way the commit graph looked when I merged main into it. I then went to the initial commit on main from the commit graph, selected it, then selected "create new branch" and gave it the same name as the old branch. Before doing so, I did do to the site administration settings > monitoring > and ran the cron job to delete old branches.

However, the web-browser displays that this branch has 16 commits, which it did at the time it was deleted.

Not sure if #3867 (closed) is related to this or not. I looked into the original commit of the branches.go module and it changed from this;

// RemoveDeletedBranch removes all deleted branches
func RemoveDeletedBranch(repoID int64, branch string) error {
    _, err := x.Where("repo_id=? AND name=?", repoID, branch).Delete(new(DeletedBranch))
    return err
}

to this

// RemoveDeletedBranchByID removes a deleted branch from the database
func RemoveDeletedBranchByID(repoID, id int64) (err error) {
    deletedBranch := &DeletedBranch{
        RepoID: repoID,
        ID:     id,
    }

    if affected, err := db.GetEngine(db.DefaultContext).Delete(deletedBranch); err != nil {
        return err
    } else if affected != 1 {
        return fmt.Errorf("remove deleted branch ID(%v) failed", id)
    }

    return nil
}

Or maybe everything is running fine, but for some reason, gitea is selecting commit history from the database for display even though the old branch was deleted?

Screenshots

branch "note-new" has been deleted and the cron job from site administration > monitoring ran manually

gitea with deleted branch

However, after selecting the initial commit from main and creating a new branch with the same name as the old one, it looks like there is history already on the main branch page.

new branch after creation

But when we look into it, there is only the initial commit, not 16 Gitea after new branch created

Also displays the lone commit in the graph, not 16 commits like the branch page indicates. gitea branch commit graph

Gitea Version

1.17.3

Can you reproduce the bug on the Gitea demo site?

No

Operating System

Ubuntu 20.04.5

Browser Version

Safari 16.0

Gregory92 commented 1 year ago

Just added a test file and committed directly to the "note-new" branch, and the commit counter reset and now correctly displays "2" commits. So it seems to just be an issue during the first initial creation of the branch with the commits getting pulled from the old "deleted" branch since the new one shares the same name?