Skip to content

Commit eafec13

Browse files
authored
Merge pull request #776 from fcollonval/fix/not-in-repository
Handle not in repository error when we are not in a repository
2 parents 342ea8b + 6e50861 commit eafec13

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

jupyterlab_git/handlers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ async def post(self):
206206
"""
207207
current_path = self.get_json_body()["current_path"]
208208
result = await self.git.branch(current_path)
209+
210+
if result["code"] != 0:
211+
self.set_status(500)
209212
self.finish(json.dumps(result))
210213

211214

src/model.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -719,16 +719,17 @@ export class GitExtension implements IGitExtension {
719719
const tid = this._addTask('git:refresh:branches');
720720
try {
721721
const response = await this._branch();
722-
if (response.code === 0) {
723-
this._branches = response.branches;
724-
this._currentBranch = response.current_branch;
725-
if (this._currentBranch) {
726-
// Set up the marker obj for the current (valid) repo/branch combination
727-
this._setMarker(this.pathRepository, this._currentBranch.name);
728-
}
729-
} else {
730-
this._branches = [];
731-
this._currentBranch = null;
722+
this._branches = response.branches;
723+
this._currentBranch = response.current_branch;
724+
if (this._currentBranch) {
725+
// Set up the marker obj for the current (valid) repo/branch combination
726+
this._setMarker(this.pathRepository, this._currentBranch.name);
727+
}
728+
} catch (error) {
729+
this._branches = [];
730+
this._currentBranch = null;
731+
if (!(error instanceof Git.NotInRepository)) {
732+
throw error;
732733
}
733734
} finally {
734735
this._removeTask(tid);
@@ -743,13 +744,17 @@ export class GitExtension implements IGitExtension {
743744
async refreshStatus(): Promise<void> {
744745
let data: Git.IStatusResult;
745746

746-
await this.ready;
747-
748-
const path = this.pathRepository;
749-
if (path === null) {
747+
let path: string;
748+
try {
749+
path = await this._getPathRespository();
750+
} catch (error) {
750751
this._setStatus([]);
751-
return Promise.resolve();
752+
if (!(error instanceof Git.NotInRepository)) {
753+
throw error;
754+
}
755+
return;
752756
}
757+
753758
const tid = this._addTask('git:refresh:status');
754759
try {
755760
data = await requestAPI<Git.IStatusResult>('status', 'POST', {

0 commit comments

Comments
 (0)