Skip to content
This repository has been archived by the owner on Sep 4, 2018. It is now read-only.

Update git submodules when updating plugins #484

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions Alcatraz/Helpers/ATZGit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ static NSString *const IGNORE_PUSH_CONFIG = @"-c push.default=matching";
static NSString *const CLONE = @"clone";
static NSString *const RECURSIVE = @"--recursive";
static NSString *const FETCH = @"fetch";
static NSString *const RECURSE_SUBMODULES_ON_DEMAND = @"--recurse-submodules=on-demand";
static NSString *const ORIGIN = @"origin";
static NSString *const BRANCH = @"branch";
static NSString *const COMMIT = @"commit";
static NSString *const TAG = @"tag";
static NSString *const ORIGIN_MASTER = @"origin/master";
static NSString *const RESET = @"reset";
static NSString *const HARD = @"--hard";
static NSString *const SUBMODULE = @"submodule";
static NSString *const UPDATE = @"update";

@interface ATZGit : NSObject

Expand Down
39 changes: 34 additions & 5 deletions Alcatraz/Helpers/ATZGit.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,42 @@ + (void)clone:(NSString *)remotePath to:(NSString *)localPath completion:(void (
}];
}

/// This will:
/// - fetch new commits from the remote;
/// - hard reset HEAD to `revision`;
/// - update submodules to match what the superproject expects at `revision`
// TODO: refactor, make less shell instances (maybe?)
+ (void)updateLocalProject:(NSString *)localPath revision:(NSString *)revision
completion:(void (^)(NSString *, NSError *))completion {

[self fetch:localPath completion:^(NSString *fetchOutput, NSError *error) {

if (error)
if (error) {
completion(fetchOutput, error);
else
[self resetHard:localPath revision:revision completion:^(NSString *resetOutput, NSError *error) {
return;
}

[self resetHard:localPath revision:revision completion:^(NSString *resetOutput, NSError *error) {
if (error) {
completion(resetOutput, error);
return;
}

[self submoduleUpdate:localPath completion:^(NSString *submoduleUpdateOutput, NSError *error) {
if (error) {
completion(submoduleUpdateOutput, error);
return;
}

completion(fetchOutput, error);
}];
}];
}];
}

+ (void)fetch:(NSString *)localPath completion:(void (^)(NSString *, NSError *))completion {

ATZShell *shell = [ATZShell new];
[shell executeCommand:[self gitExecutablePath] withArguments:@[FETCH, ORIGIN] inWorkingDirectory:localPath
[shell executeCommand:[self gitExecutablePath] withArguments:@[FETCH, RECURSE_SUBMODULES_ON_DEMAND, ORIGIN] inWorkingDirectory:localPath
completion:^(NSString *output, NSError *error) {

NSLog(@"Git fetch output: %@", output);
Expand All @@ -126,6 +143,18 @@ + (void)resetHard:(NSString *)localPath revision:(NSString *)revision
}];
}

+ (void)submoduleUpdate:(NSString *)localPath completion:(void (^)(NSString *, NSError *))completion {

ATZShell *shell = [ATZShell new];

[shell executeCommand:[self gitExecutablePath] withArguments:@[SUBMODULE, UPDATE] inWorkingDirectory:localPath
completion:^(NSString *output, NSError *error) {

NSLog(@"Git submodule update output: %@", output);
completion(output, error);
}];
}



@end
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased
- Support GIF image on screenshot preview (#432)
- Git submodules are now updated when fetching plugins updates (#484)

## 1.2.0

Expand Down