Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixup git reset helper to use checkout when file resets are requested #1326

Merged
merged 1 commit into from
Jul 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/app/FakeLib/Git/Reset.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
module Fake.Git.Reset

open System
open Fake
open Fake.Git.CommandHelper

let internal addArgs commit file =
sprintf "%s%s"
(if String.IsNullOrEmpty commit then "" else " \"" + commit + "\"")
(if String.IsNullOrEmpty file then "" else " -- \"" + file + "\"")

/// the intent of the 'reset' helper is to either set a repo to a certain point, or set a file to a certain point. Git reset doesn't take file paths in the hard/mixed/soft modes, and so you have to use checkout instead for that.
/// This function encapsulates caring about that so you don't have to.
let internal resetOrCheckout file mode =
match file |> String.IsNullOrEmpty with
| true -> sprintf "reset --%s" mode
| false -> "checkout"

/// Performs a git reset "soft".
/// Does not touch the index file nor the working tree at all.
/// ## Parameters
///
/// - `repositoryDir` - The git repository.
/// - `commit` - The commit to which git should perform the reset.
/// - `file` - The file to reset - null means all files.
let soft repositoryDir commit file = "reset --soft" + addArgs commit file |> gitCommand repositoryDir
let soft repositoryDir commit file = resetOrCheckout file "soft" + addArgs commit file |> gitCommand repositoryDir

/// Performs a git reset "mixed".
/// Resets the index but not the working tree and reports what has not been updated.
Expand All @@ -26,7 +33,7 @@ let soft repositoryDir commit file = "reset --soft" + addArgs commit file |> git
/// - `repositoryDir` - The git repository.
/// - `commit` - The commit to which git should perform the reset.
/// - `file` - The file to reset - null means all files.
let mixed repositoryDir commit file = "reset --mixed" + addArgs commit file |> gitCommand repositoryDir
let mixed repositoryDir commit file = resetOrCheckout file "mixed" + addArgs commit file |> gitCommand repositoryDir

/// Performs a git reset "hard".
/// Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
Expand All @@ -35,7 +42,7 @@ let mixed repositoryDir commit file = "reset --mixed" + addArgs commit file |> g
/// - `repositoryDir` - The git repository.
/// - `commit` - The commit to which git should perform the reset.
/// - `file` - The file to reset - null means all files.
let hard repositoryDir commit file = "reset --hard" + addArgs commit file |> gitCommand repositoryDir
let hard repositoryDir commit file = resetOrCheckout file "hard" + addArgs commit file |> gitCommand repositoryDir

/// Performs a git reset "soft" to the current HEAD.
/// Does not touch the index file nor the working tree at all.
Expand Down