Commit with "Initial commit" if there is no parent
This commit is contained in:
parent
ffd71b0907
commit
9e5932f57c
1 changed files with 17 additions and 11 deletions
|
@ -138,24 +138,30 @@ impl StoreIdAccessor for CreateHook {
|
||||||
repo.head()
|
repo.head()
|
||||||
.map_dbg_err_str("[GIT CREATE HOOK]: Couldn't fetch HEAD")
|
.map_dbg_err_str("[GIT CREATE HOOK]: Couldn't fetch HEAD")
|
||||||
.map_err_into(GHEK::RepositoryHeadFetchingError)
|
.map_err_into(GHEK::RepositoryHeadFetchingError)
|
||||||
.and_then(|h| {
|
.map(|h| h.target())
|
||||||
h.target().ok_or(GHEK::RepositoryHeadTargetFetchingError.into_error())
|
|
||||||
})
|
|
||||||
.and_then(|oid| {
|
.and_then(|oid| {
|
||||||
repo.find_commit(oid)
|
match oid {
|
||||||
.map_dbg_err_str("[GIT CREATE HOOK]: Couldn't find commit")
|
Some(oid) => {
|
||||||
.map_dbg_err(|_| format!("\toid = {:?}", oid))
|
repo.find_commit(oid)
|
||||||
.map_err_into(GHEK::RepositoryCommitFindingError)
|
.map(|c| Some(c))
|
||||||
|
.map_dbg_err_str("[GIT CREATE HOOK]: Couldn't find commit")
|
||||||
|
.map_dbg_err(|_| format!("\toid = {:?}", oid))
|
||||||
|
.map_err_into(GHEK::RepositoryCommitFindingError)
|
||||||
|
},
|
||||||
|
None => Ok(None),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.map_err_into(GHEK::RepositoryError)
|
.map_err_into(GHEK::RepositoryError)
|
||||||
.map_err(|e| e.into())
|
.map_err(|e| e.into())
|
||||||
.map(|parent| (repo, cfg, sig, idx, tree, parent))
|
.map(|parent| (repo, cfg, sig, idx, tree, parent))
|
||||||
})
|
})
|
||||||
.and_then(|(repo, cfg, sig, idx, tree, parent)| {
|
.and_then(|(repo, cfg, sig, idx, tree, opt_parent)| {
|
||||||
let mut parents = vec![];
|
let (msg, parents) = match opt_parent {
|
||||||
parents.push(parent);
|
None => (String::from("Initial commit"), vec![]),
|
||||||
|
Some(p) => (commit_message(&cfg, StoreAction::Create), vec![p]),
|
||||||
|
};
|
||||||
|
|
||||||
let parents = parents.iter().collect::<Vec<_>>();
|
let parents = parents.iter().collect::<Vec<_>>();
|
||||||
let msg = commit_message(&cfg, StoreAction::Create);
|
|
||||||
repo.commit(Some("HEAD"), &sig, &sig, &msg[..], &tree, &parents)
|
repo.commit(Some("HEAD"), &sig, &sig, &msg[..], &tree, &parents)
|
||||||
.map_dbg_err_str("[GIT CREATE HOOK]: Couldn't commit")
|
.map_dbg_err_str("[GIT CREATE HOOK]: Couldn't commit")
|
||||||
.map_err_into(GHEK::RepositoryCommittingError)
|
.map_err_into(GHEK::RepositoryCommittingError)
|
||||||
|
|
Loading…
Reference in a new issue