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

Feature: Added support for initializing folders as Git repos #12803

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/Files.App/Actions/Git/GitFetchAction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Files.App.Contexts;
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Contexts;

namespace Files.App.Actions
{
Expand Down
48 changes: 48 additions & 0 deletions src/Files.App/Actions/Git/GitInitAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Contexts;

namespace Files.App.Actions
{
sealed class GitInitAction : ObservableObject, IAction
{
private readonly IContentPageContext _context;

public string Label
=> "Init".GetLocalizedResource();

public string Description
=> "InitRepositoryDescription".GetLocalizedResource();

public bool IsExecutable =>
(_context.SelectedItem is not null ||
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
_context.Folder is not null) &&
!_context.IsGitRepository;

public GitInitAction()
{
_context = Ioc.Default.GetRequiredService<IContentPageContext>();

_context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
{
GitHelpers.InitializeRepository(_context.SelectedItem?.ItemPath ?? _context.Folder?.ItemPath);
return Task.CompletedTask;
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.Folder):
case nameof(IContentPageContext.SelectedItem):
case nameof(IContentPageContext.IsGitRepository):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
5 changes: 4 additions & 1 deletion src/Files.App/Actions/Git/GitPullAction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Files.App.Commands;
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Contexts;

namespace Files.App.Actions
Expand Down
5 changes: 4 additions & 1 deletion src/Files.App/Actions/Git/GitPushAction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Files.App.Commands;
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Contexts;

namespace Files.App.Actions
Expand Down
5 changes: 4 additions & 1 deletion src/Files.App/Actions/Git/GitSyncAction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Files.App.Commands;
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Commands;
using Files.App.Contexts;

namespace Files.App.Actions
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public enum CommandCodes

// Git
GitFetch,
GitInit,
GitPull,
GitPush,
GitSync,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand OpenFileLocation => commands[CommandCodes.OpenFileLocation];
public IRichCommand PlayAll => commands[CommandCodes.PlayAll];
public IRichCommand GitFetch => commands[CommandCodes.GitFetch];
public IRichCommand GitInit => commands[CommandCodes.GitInit];
public IRichCommand GitPull => commands[CommandCodes.GitPull];
public IRichCommand GitPush => commands[CommandCodes.GitPush];
public IRichCommand GitSync => commands[CommandCodes.GitSync];
Expand Down Expand Up @@ -313,6 +314,7 @@ public CommandManager()
[CommandCodes.OpenFileLocation] = new OpenFileLocationAction(),
[CommandCodes.PlayAll] = new PlayAllAction(),
[CommandCodes.GitFetch] = new GitFetchAction(),
[CommandCodes.GitInit] = new GitInitAction(),
[CommandCodes.GitPull] = new GitPullAction(),
[CommandCodes.GitPush] = new GitPushAction(),
[CommandCodes.GitSync] = new GitSyncAction(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand PlayAll { get; }

IRichCommand GitFetch { get; }
IRichCommand GitInit { get; }
IRichCommand GitPull { get; }
IRichCommand GitPush { get; }
IRichCommand GitSync { get; }
Expand Down
8 changes: 8 additions & 0 deletions src/Files.App/Helpers/GitHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ public static GitItemModel GetGitInformationForItem(Repository repository, strin
return gitItemModel;
}

public static void InitializeRepository(string? path)
{
if (string.IsNullOrWhiteSpace(path))
return;

Repository.Init(path);
}

private static Commit? GetLastCommitForFile(Repository repository, string currentPath)
{
foreach (var currentCommit in repository.Commits)
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3374,4 +3374,10 @@
<data name="AuthorizationSucceded">
<value>Great! You are now authorized.</value>
</data>
<data name="Init" xml:space="preserve">
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
<value>Initialize</value>
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="InitRepositoryDescription" xml:space="preserve">
<value>Initialize a git repository</value>
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
</data>
</root>