Skip to content

Commit

Permalink
Downstream repository is checked for uncommitted changes and commits …
Browse files Browse the repository at this point in the history
…made in detached HEAD state when `update`ing/`restore`ing Git dependency

Checking for uncommitted changes prevents hard-to-track bugs as well as non-repeatable builds that might occur by merging user's changes into the new working directory.
Checking for detached commits makes working in the downstream repository safer - it saves the user from having to inspect reflog after "losing" her commits.
It also forces the user to move the changes to a permanent branch when making meaningful changes.
  • Loading branch information
tomasdeml committed Apr 11, 2017
1 parent c398909 commit 117cad1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Paket.Core/GitHandling.fs
Expand Up @@ -158,6 +158,20 @@ let fetchCache repoCacheFolder cloneUrl =
with
| exn -> failwithf "Fetching the git cache at %s failed.%sMessage: %s" repoCacheFolder Environment.NewLine exn.Message

let checkForUncommittedChanges repoFolder =
try
tracefn "Checking for uncommitted changes in %s" repoFolder
CommandHelper.gitCommand repoFolder "diff-index --quiet HEAD --" |> ignore
with
| exn -> failwithf "It seems there are uncommitted changes in the repository. The changes must be committed/discarded first.%sMessage: %s" Environment.NewLine exn.Message

let checkForCommitsMadeInDetachedHeadState repoFolder =
try
tracefn "Checking for commits made in detached HEAD state in %s" repoFolder
CommandHelper.gitCommand repoFolder "name-rev --no-undefined HEAD --" |> ignore
with
| exn -> failwithf "It seems that some commits would become unreachable after checkout. Create branch for the commits or reset them first and try again.%sMessage: %s" Environment.NewLine exn.Message

let tagCommitForCheckout repoFolder commit =
try
CommandHelper.runSimpleGitCommand repoFolder (sprintf "tag -f %s %s" paketCheckoutTag commit) |> ignore
Expand All @@ -181,6 +195,9 @@ let checkoutToPaketFolder repoFolder cloneUrl cacheCloneUrl commit =
CommandHelper.runSimpleGitCommand destination (sprintf "clone %s %s" (quote cacheCloneUrl) (quote repoFolder)) |> ignore
CommandHelper.runSimpleGitCommand repoFolder (sprintf "remote set-url origin %s" <| quote cloneUrl) |> ignore

checkForUncommittedChanges repoFolder
checkForCommitsMadeInDetachedHeadState repoFolder

tracefn "Setting %s to %s" repoFolder commit
tagCommitForCheckout repoFolder commit
checkoutTaggedCommit repoFolder
Expand Down

0 comments on commit 117cad1

Please sign in to comment.