From 392c6dc41bb7977652e4e663622c149b07a97c2f Mon Sep 17 00:00:00 2001 From: lapfelix Date: Mon, 15 Apr 2024 22:11:54 -0400 Subject: [PATCH] Add and implement `kGCCheckoutOption_RemoveUntrackedFiles` ...to fix issue where untracked files are left behind after forceCheckoutHEAD is called during a rebase --- GitUpKit/Core/GCRepository+HEAD.h | 3 ++- GitUpKit/Core/GCRepository+HEAD.m | 5 +++++ GitUpKit/Extensions/GCRepository+Utilities.m | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/GitUpKit/Core/GCRepository+HEAD.h b/GitUpKit/Core/GCRepository+HEAD.h index 0faa8d02..7c439735 100644 --- a/GitUpKit/Core/GCRepository+HEAD.h +++ b/GitUpKit/Core/GCRepository+HEAD.h @@ -17,7 +17,8 @@ typedef NS_OPTIONS(NSUInteger, GCCheckoutOptions) { kGCCheckoutOption_Force = (1 << 0), - kGCCheckoutOption_UpdateSubmodulesRecursively = (1 << 1) + kGCCheckoutOption_UpdateSubmodulesRecursively = (1 << 1), + kGCCheckoutOption_RemoveUntrackedFiles = (1 << 2), }; @interface GCRepository (HEAD) diff --git a/GitUpKit/Core/GCRepository+HEAD.m b/GitUpKit/Core/GCRepository+HEAD.m index 99ade36a..352300ae 100644 --- a/GitUpKit/Core/GCRepository+HEAD.m +++ b/GitUpKit/Core/GCRepository+HEAD.m @@ -194,6 +194,11 @@ - (BOOL)_checkoutTreeForCommit:(GCCommit*)commit git_tree* tree = NULL; git_checkout_options checkoutOptions = GIT_CHECKOUT_OPTIONS_INIT; checkoutOptions.checkout_strategy = options & kGCCheckoutOption_Force ? GIT_CHECKOUT_FORCE : GIT_CHECKOUT_SAFE; + + if (options & kGCCheckoutOption_RemoveUntrackedFiles) { + checkoutOptions.checkout_strategy |= GIT_CHECKOUT_REMOVE_UNTRACKED; + } + if (baseline) { CALL_LIBGIT2_FUNCTION_RETURN(NO, git_commit_tree, &tree, baseline.private); checkoutOptions.baseline = tree; diff --git a/GitUpKit/Extensions/GCRepository+Utilities.m b/GitUpKit/Extensions/GCRepository+Utilities.m index 765b114d..b30efaf2 100644 --- a/GitUpKit/Extensions/GCRepository+Utilities.m +++ b/GitUpKit/Extensions/GCRepository+Utilities.m @@ -292,7 +292,7 @@ - (BOOL)forceCheckoutHEAD:(BOOL)recursive error:(NSError**)error { if (![self lookupHEADCurrentCommit:&headCommit branch:NULL error:error]) { return NO; } - GCCheckoutOptions options = kGCCheckoutOption_Force; + GCCheckoutOptions options = kGCCheckoutOption_Force | kGCCheckoutOption_RemoveUntrackedFiles; if (recursive) { options |= kGCCheckoutOption_UpdateSubmodulesRecursively; }