Skip to content

Commit

Permalink
Merge pull request atom#10507 from atom/handle-broken-submodules
Browse files Browse the repository at this point in the history
Handle broken submodules
  • Loading branch information
joshaber committed Jan 20, 2016
2 parents a797c9b + 60c33f6 commit 1be4453
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/git-repository-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ export default class GitRepositoryAsync {
this.emitter = new Emitter()
this.subscriptions = new CompositeDisposable()
this.pathStatusCache = {}
// NB: This needs to happen before the following .openRepository call.

// NB: These needs to happen before the following .openRepository call.
this.openedPath = _path
this._openExactPath = options.openExactPath || false

this.repoPromise = this.openRepository()
this.isCaseInsensitive = fs.isCaseInsensitive()
this.upstream = {}
Expand Down Expand Up @@ -848,22 +851,30 @@ export default class GitRepositoryAsync {

const submodule = await Git.Submodule.lookup(repo, name)
const absolutePath = path.join(repo.workdir(), submodule.path())
const submoduleRepo = GitRepositoryAsync.open(absolutePath)
const submoduleRepo = GitRepositoryAsync.open(absolutePath, {openExactPath: true, refreshOnWindowFocus: false})
this.submodules[name] = submoduleRepo
}

for (const name in this.submodules) {
if (submoduleNames.indexOf(name) < 0) {
const repo = this.submodules[name]
const repo = this.submodules[name]
const gone = submoduleNames.indexOf(name) < 0
if (gone) {
repo.destroy()
delete this.submodules[name]
} else {
try {
await repo.refreshStatus()
} catch (e) {
// libgit2 will sometimes report submodules that aren't actually valid
// (https://github.com/libgit2/libgit2/issues/3580). So check the
// validity of the submodules by removing any that fail.
repo.destroy()
delete this.submodules[name]
}
}
}

const submoduleRepos = _.values(this.submodules)
await Promise.all(submoduleRepos.map(s => s.refreshStatus()))

return submoduleRepos
return _.values(this.submodules)
}

// Get the status for the submodules in the repository.
Expand Down Expand Up @@ -969,7 +980,11 @@ export default class GitRepositoryAsync {
//
// Returns the new {NodeGit.Repository}.
openRepository () {
return Git.Repository.openExt(this.openedPath, 0, '')
if (this._openExactPath) {
return Git.Repository.open(this.openedPath)
} else {
return Git.Repository.openExt(this.openedPath, 0, '')
}
}

// Section: Private
Expand Down

0 comments on commit 1be4453

Please sign in to comment.