Skip to content

Commit

Permalink
Merge pull request #776 from fcollonval/fix/not-in-repository
Browse files Browse the repository at this point in the history
Handle not in repository error when we are not in a repository
  • Loading branch information
fcollonval authored Sep 18, 2020
2 parents 342ea8b + 6e50861 commit eafec13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
3 changes: 3 additions & 0 deletions jupyterlab_git/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ async def post(self):
"""
current_path = self.get_json_body()["current_path"]
result = await self.git.branch(current_path)

if result["code"] != 0:
self.set_status(500)
self.finish(json.dumps(result))


Expand Down
35 changes: 20 additions & 15 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,16 +719,17 @@ export class GitExtension implements IGitExtension {
const tid = this._addTask('git:refresh:branches');
try {
const response = await this._branch();
if (response.code === 0) {
this._branches = response.branches;
this._currentBranch = response.current_branch;
if (this._currentBranch) {
// Set up the marker obj for the current (valid) repo/branch combination
this._setMarker(this.pathRepository, this._currentBranch.name);
}
} else {
this._branches = [];
this._currentBranch = null;
this._branches = response.branches;
this._currentBranch = response.current_branch;
if (this._currentBranch) {
// Set up the marker obj for the current (valid) repo/branch combination
this._setMarker(this.pathRepository, this._currentBranch.name);
}
} catch (error) {
this._branches = [];
this._currentBranch = null;
if (!(error instanceof Git.NotInRepository)) {
throw error;
}
} finally {
this._removeTask(tid);
Expand All @@ -743,13 +744,17 @@ export class GitExtension implements IGitExtension {
async refreshStatus(): Promise<void> {
let data: Git.IStatusResult;

await this.ready;

const path = this.pathRepository;
if (path === null) {
let path: string;
try {
path = await this._getPathRespository();
} catch (error) {
this._setStatus([]);
return Promise.resolve();
if (!(error instanceof Git.NotInRepository)) {
throw error;
}
return;
}

const tid = this._addTask('git:refresh:status');
try {
data = await requestAPI<Git.IStatusResult>('status', 'POST', {
Expand Down

0 comments on commit eafec13

Please sign in to comment.