-
Root cause
The git repo browsing is implemented using Jgit on com.sztab.controller.project.git.ProjectGitController.
if (Files.exists(repoPath.resolve(".git"))) { Git git = Git.open(repoPath.toFile()); git.fetch() .setCredentialsProvider(getCredentials(project)) .call(); return git; } else { // Clone the repository Files.createDirectories(repoPath); return Git.cloneRepository() // <= clones the empty repo ...When the repo is first browsed while empty, it clones an empty repo into the temp dir. On the next request (after the user has pushed), the .git dir exists so it takes the fetch path — but git fetch on an empty remote with no refs does nothing and leaves the local clone still empty. The local clone is permanently stuck in its empty initial state. There are actually two bugs layered here:
- fetch() with no refspec doesn't pull down newly created branches/refs on a previously-empty repo
- repo.resolve("refs/heads/" + branchName) resolves against the local clone, so a stale clone will always miss new commits.
-
Fix
The fix is to always do a proper fetch with a refspec, and to handle the case where the remote gained its first branch after the clone:
private Git getGitRepo(Project project) throws Exception { Path repoPath = tempDir.resolve("project-" + project.getId()); if (Files.exists(repoPath.resolve(".git"))) { Git git = Git.open(repoPath.toFile()); // Fetch all refs, including newly created branches on a previously-empty remote. // The default fetch() with no refspec silently does nothing if the remote // had no branches at clone time (no tracking refs configured). git.fetch() .setCredentialsProvider(getCredentials(project)) .setRefSpecs("+refs/heads/*:refs/heads/*") // force-update all remote branches locally .call(); return git; } else { Files.createDirectories(repoPath); return Git.cloneRepository() .setURI(project.getGitUrl()) .setDirectory(repoPath.toFile()) .setCredentialsProvider(getCredentials(project)) .call(); } }The refspec +refs/heads/:refs/heads/ force-maps every remote branch directly to a local branch ref, bypassing the tracking-ref machinery that breaks when the clone was empty. The + prefix means force-update even if the local ref doesn't fast-forward cleanly.
-
Pull Request under review: https://tigase.dev/sztab/~pulls/15
-
rksuma@Ramakrishnans-MacBook-Pro backend % git push --set-upstream origin bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push Enumerating objects: 35, done. Counting objects: 100% (35/35), done. Delta compression using up to 12 threads Compressing objects: 100% (16/16), done. Writing objects: 100% (20/20), 4.45 KiB | 4.45 MiB/s, done. Total 20 (delta 7), reused 0 (delta 0), pack-reused 0 (from 0) remote: remote: Create a pull request for 'bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push' by visiting: remote: https://tigase.dev/sztab/~pulls/new?target=1325:wolnosc&source=1325:bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push remote: To https://tigase.dev/sztab.git * [new branch] bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push -> bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push branch 'bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push' set up to track 'origin/bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push'. rksuma@Ramakrishnans-MacBook-Pro backend % git status On branch bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push Your branch is up to date with 'origin/bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push'. nothing to commit, working tree clean rksuma@Ramakrishnans-MacBook-Pro backend % git checkout wolnosc git pull origin wolnosc git merge bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push git push origin wolnosc Switched to branch 'wolnosc' Your branch is up to date with 'origin/wolnosc'. From https://tigase.dev/sztab * branch wolnosc -> FETCH_HEAD Already up to date. Updating 8814017..ccd061c Fast-forward backend/src/main/java/com/sztab/controller/project/git/ProjectGitController.java | 156 ++++++++++++++++++++++++++++++++++++++++++++++++--------------------- backend/src/test/java/com/sztab/controller/project/git/ProjectGitControllerTest.java | 18 ++++++-- 2 files changed, 123 insertions(+), 51 deletions(-) Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) To https://tigase.dev/sztab.git 8814017..ccd061c wolnosc -> wolnosc rksuma@Ramakrishnans-MacBook-Pro backend % git push origin --delete bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push remote: remote: Create a pull request for 'bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push' by visiting: remote: https://tigase.dev/sztab/~pulls/new?target=1325:wolnosc&source=1325:bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push remote: To https://tigase.dev/sztab.git - [deleted] bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push rksuma@Ramakrishnans-MacBook-Pro backend % git branch -d bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push Deleted branch bugfix/SZ-108-Repository-browser-does-not-refresh-after-first-push (was ccd061c). rksuma@Ramakrishnans-MacBook-Pro backend %
| Type |
Bug
|
| Priority |
Major
|
| Assignee | |
| Version |
1.9.1
|
| Sprints |
n/a
|
| Customer |
n/a
|
Description
Steps to reproduce:
Observed behavior: The web UI still shows the repository as empty.
There is no visible way to refresh repository state.
Expected Behavior
On page load, the repository browser should:
Repository state should not be cached as permanently empty.
Impact
Creates confusion and makes repository appear broken after first push.
Acceptance Criteria