mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 17:16:15 +02:00
git fetcher: distinguish errors more precisely
This commit is contained in:
parent
c7e527b82b
commit
9504445cab
2 changed files with 25 additions and 9 deletions
|
@ -222,17 +222,25 @@ struct GitInputScheme : InputScheme
|
||||||
|
|
||||||
/* Check whether HEAD points to something that looks like a commit,
|
/* Check whether HEAD points to something that looks like a commit,
|
||||||
since that is the refrence we want to use later on. */
|
since that is the refrence we want to use later on. */
|
||||||
bool hasHead = false;
|
auto result = runProgram(RunOptions {
|
||||||
try {
|
.program = "git",
|
||||||
runProgram("git", true, { "-C", actualUrl, "rev-parse", "--verify", "--no-revs", "HEAD^{commit}" });
|
.args = { "-C", actualUrl, "--git-dir=.git", "rev-parse", "--verify", "--no-revs", "HEAD^{commit}" },
|
||||||
hasHead = true;
|
.mergeStderrToStdout = true
|
||||||
} catch (ExecError & e) {
|
});
|
||||||
// git exits with status 128 here if it does not detect a repository.
|
auto exitCode = WEXITSTATUS(result.first);
|
||||||
if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 128) {
|
auto errorMessage = result.second;
|
||||||
throw Error("Git tree '%s' is broken.\n'git rev-parse --verify HEAD' failed with exit code %d.", actualUrl, WEXITSTATUS(e.status));
|
|
||||||
}
|
if (errorMessage.find("fatal: not a git repository") != std::string::npos) {
|
||||||
|
throw Error("'%s' is not a git repository.", actualUrl);
|
||||||
|
} else if (errorMessage.find("fatal: Needed a single revision") != std::string::npos) {
|
||||||
|
// indicates that the repo does not have any commits
|
||||||
|
// we want to proceed and will consider it dirty later
|
||||||
|
} else if (exitCode != 0) {
|
||||||
|
// any other errors should lead to a failure
|
||||||
|
throw Error("Getting the HEAD of the git tree '%s' failed with exit code %d:\n%s", actualUrl, exitCode, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasHead = exitCode == 0;
|
||||||
try {
|
try {
|
||||||
if (hasHead) {
|
if (hasHead) {
|
||||||
// Using git diff is preferrable over lower-level operations here,
|
// Using git diff is preferrable over lower-level operations here,
|
||||||
|
|
|
@ -206,3 +206,11 @@ rev4_nix=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$
|
||||||
# The name argument should be handled
|
# The name argument should be handled
|
||||||
path9=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; name = \"foo\"; }).outPath")
|
path9=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; name = \"foo\"; }).outPath")
|
||||||
[[ $path9 =~ -foo$ ]]
|
[[ $path9 =~ -foo$ ]]
|
||||||
|
|
||||||
|
# should fail if there is no repo
|
||||||
|
rm -rf $repo/.git
|
||||||
|
(! nix eval --impure --raw --expr "(builtins.fetchGit \"file://$repo\").outPath")
|
||||||
|
|
||||||
|
# should succeed for a repo without commits
|
||||||
|
git init $repo
|
||||||
|
path10=$(nix eval --impure --raw --expr "(builtins.fetchGit \"file://$repo\").outPath")
|
||||||
|
|
Loading…
Reference in a new issue