Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix: preserve merge states in submodules (#769)
* fix: preserve merge states in submodules * test: set git user details into submodule dir for Windows * fix: resolve absolute git config dir in submodule case * fix: use String.prototype.trim() to remove whitespace from shell output
- Loading branch information
Showing
9 changed files
with
130 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict' | ||
|
||
const normalize = require('normalize-path') | ||
const path = require('path') | ||
|
||
const execGit = require('./execGit') | ||
const { readBufferFromFile } = require('./file') | ||
|
||
/** | ||
* Resolve path to the .git directory, with special handling for | ||
* submodules | ||
*/ | ||
const resolveGitConfigDir = async ({ gitDir, isSubmodule }) => { | ||
const defaultDir = path.resolve(gitDir, '.git') | ||
if (!isSubmodule) return normalize(defaultDir) | ||
|
||
const buffer = await readBufferFromFile(defaultDir) | ||
const dotGit = buffer.toString() | ||
const gitConfigDir = path.resolve(gitDir, dotGit.replace(/^gitdir: /, '').trim()) | ||
return normalize(gitConfigDir) | ||
} | ||
|
||
/** | ||
* Resolve git directory and possible submodule paths | ||
*/ | ||
module.exports = async function resolveGitRepo(options = {}) { | ||
try { | ||
// git cli uses GIT_DIR to fast track its response however it might be set to a different path | ||
// depending on where the caller initiated this from, hence clear GIT_DIR | ||
delete process.env.GIT_DIR | ||
|
||
// The git repo root directory; this points to the root of a submodule instead of the parent | ||
const gitDir = await execGit(['rev-parse', '--show-toplevel'], options) | ||
|
||
// A super-project working tree exists only in submodules; poinst to the parent root | ||
const superprojectWorkingTree = await execGit( | ||
['rev-parse', '--show-superproject-working-tree'], | ||
options | ||
) | ||
|
||
const isSubmodule = !!superprojectWorkingTree | ||
const gitConfigDir = await resolveGitConfigDir({ gitDir, isSubmodule }) | ||
|
||
return { gitDir: normalize(gitDir), gitConfigDir, isSubmodule } | ||
} catch (error) { | ||
return { error, gitDir: null } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters