Skip to content

Add support for pruning and ignoring tags during fetch #561

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

Merged
merged 1 commit into from
Mar 10, 2016
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions ObjectiveGit/GTRepository+Pull.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ typedef void (^GTRemoteFetchTransferProgressBlock)(const git_transfer_progress *
/// options - Options applied to the fetch operation.
/// Recognized options are:
/// `GTRepositoryRemoteOptionsCredentialProvider`
/// `GTRepositoryRemoteOptionsFetchPrune`
/// `GTRepositoryRemoteOptionsDownloadTags`
/// error - The error if one occurred. Can be NULL.
/// progressBlock - An optional callback for monitoring progress.
///
Expand Down
17 changes: 17 additions & 0 deletions ObjectiveGit/GTRepository+RemoteOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "GTRepository.h"
#import "git2/remote.h"

@class GTFetchHeadEntry;

Expand All @@ -15,6 +16,20 @@ NS_ASSUME_NONNULL_BEGIN
/// A `GTCredentialProvider`, that will be used to authenticate against the remote.
extern NSString *const GTRepositoryRemoteOptionsCredentialProvider;

/// A `GTFetchPruneOption`, that will be used to determine if the fetch should prune or not.
extern NSString *const GTRepositoryRemoteOptionsFetchPrune;

/// A `GTRemoteAutoTagOption`, that will be used to determine how the fetch should handle tags.
extern NSString *const GTRepositoryRemoteOptionsDownloadTags;

/// An enum describing the data needed for pruning.
/// See `git_fetch_prune_t`.
typedef NS_ENUM(NSInteger, GTFetchPruneOption) {
GTFetchPruneOptionUnspecified = GIT_FETCH_PRUNE_UNSPECIFIED,
GTFetchPruneOptionYes = GIT_FETCH_PRUNE,
GTFetchPruneOptionNo = GIT_FETCH_NO_PRUNE,
};

@interface GTRepository (RemoteOperations)

#pragma mark - Fetch
Expand All @@ -25,6 +40,8 @@ extern NSString *const GTRepositoryRemoteOptionsCredentialProvider;
/// options - Options applied to the fetch operation. May be nil.
/// Recognized options are :
/// `GTRepositoryRemoteOptionsCredentialProvider`
/// `GTRepositoryRemoteOptionsFetchPrune`
/// `GTRepositoryRemoteOptionsDownloadTags`
/// error - The error if one occurred. Can be NULL.
/// progressBlock - Optional callback to receive fetch progress stats during the
/// transfer. May be nil.
Expand Down
4 changes: 4 additions & 0 deletions ObjectiveGit/GTRepository+RemoteOperations.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#import "git2/remote.h"

NSString *const GTRepositoryRemoteOptionsCredentialProvider = @"GTRepositoryRemoteOptionsCredentialProvider";
NSString *const GTRepositoryRemoteOptionsFetchPrune = @"GTRepositoryRemoteOptionsFetchPrune";
NSString *const GTRepositoryRemoteOptionsDownloadTags = @"GTRepositoryRemoteOptionsDownloadTags";

typedef void (^GTRemoteFetchTransferProgressBlock)(const git_transfer_progress *stats, BOOL *stop);
typedef void (^GTRemotePushTransferProgressBlock)(unsigned int current, unsigned int total, size_t bytes, BOOL *stop);
Expand Down Expand Up @@ -80,6 +82,8 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error

git_fetch_options fetchOptions = GIT_FETCH_OPTIONS_INIT;
fetchOptions.callbacks = remote_callbacks;
fetchOptions.prune = [options[GTRepositoryRemoteOptionsFetchPrune] unsignedIntValue];
fetchOptions.download_tags = [options[GTRepositoryRemoteOptionsDownloadTags] unsignedIntValue];

__block git_strarray refspecs;
int gitError = git_remote_get_fetch_refspecs(&refspecs, remote.git_remote);
Expand Down