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 pushing Git commits #12633

Merged
merged 29 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b61ca54
Feature: Support for pushing changes
ferrariofilippo Jun 8, 2023
0a69cc7
Tooltips
ferrariofilippo Jun 9, 2023
7812d9e
Update tooltip
ferrariofilippo Jun 9, 2023
ff2156e
Merge
ferrariofilippo Jun 14, 2023
44ef185
Handle Login
ferrariofilippo Jun 16, 2023
6042916
Merge branch 'main' into Git_Push
ferrariofilippo Jun 16, 2023
0e09857
Merge leftovers
ferrariofilippo Jun 16, 2023
58cc802
Requested Changes
ferrariofilippo Jun 17, 2023
034f86b
Requested Changes
ferrariofilippo Jun 18, 2023
ddb7b5a
Merge branch 'main' into Git_Push
yaira2 Jun 19, 2023
dc635a5
Build pipeline
yaira2 Jun 19, 2023
81e7b0c
Merge branch 'main' into Git_Push
yaira2 Jun 19, 2023
8348eaa
Fix requests
ferrariofilippo Jun 19, 2023
e3d90ff
Device Flow not working
ferrariofilippo Jun 20, 2023
0316d2e
Remove " from token
ferrariofilippo Jun 20, 2023
d1aa133
Bug Fix & Copy Button
ferrariofilippo Jun 20, 2023
cbde437
Copy Button
ferrariofilippo Jun 20, 2023
97189e4
Update Dialog
ferrariofilippo Jun 21, 2023
fe50c5d
Merge branch 'main' into Git_Push
ferrariofilippo Jun 21, 2023
900bffe
Update modal
ferrariofilippo Jun 22, 2023
1b4369b
Icons
yaira2 Jun 26, 2023
077243c
Update StatusBarControl.xaml
yaira2 Jun 26, 2023
2818605
Tweak path
yaira2 Jun 27, 2023
e8993a2
Update PathIcons.xaml
yaira2 Jun 27, 2023
02dab93
Update PathIcons.xaml
yaira2 Jun 27, 2023
e84ed91
Partial Requested Changes
ferrariofilippo Jun 27, 2023
efaba3e
Remaining Requested changes
ferrariofilippo Jun 27, 2023
90eb0be
Merge
ferrariofilippo Jun 27, 2023
09af69e
Update PathIcons.xaml
yaira2 Jun 27, 2023
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
11 changes: 11 additions & 0 deletions builds/azure-pipelines-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ jobs:
}
failOnStderr: true

# Injects the GitHub token to the project
- task: PowerShell@2
displayName: 'Inject AppCenter token'
inputs:
targetType: 'inline'
script: |
gci $(Build.SourcesDirectory)\src -Include *.cs -recurse | ForEach -Process {
(Get-Content $_ -Raw | ForEach -Process {$_ -replace "githubclientid.secret", "$(githubclientid.secret)"}) | Set-Content $_ -NoNewline
}
failOnStderr: true

- task: UseDotNet@2
inputs:
packageType: sdk
Expand Down
22 changes: 22 additions & 0 deletions builds/azure-pipelines-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ jobs:
}
failOnStderr: true

# Injects the GitHub token to the project
- task: PowerShell@2
displayName: 'Inject AppCenter token'
inputs:
targetType: 'inline'
script: |
gci $(Build.SourcesDirectory)\src -Include *.cs -recurse | ForEach -Process {
(Get-Content $_ -Raw | ForEach -Process {$_ -replace "githubclientid.secret", "$(githubclientid.secret)"}) | Set-Content $_ -NoNewline
}
failOnStderr: true

- task: UseDotNet@2
inputs:
packageType: sdk
Expand Down Expand Up @@ -215,6 +226,17 @@ jobs:
}
failOnStderr: true

# Injects the GitHub token to the project
- task: PowerShell@2
displayName: 'Inject AppCenter token'
inputs:
targetType: 'inline'
script: |
gci $(Build.SourcesDirectory)\src -Include *.cs -recurse | ForEach -Process {
(Get-Content $_ -Raw | ForEach -Process {$_ -replace "githubclientid.secret", "$(githubclientid.secret)"}) | Set-Content $_ -NoNewline
}
failOnStderr: true

- task: UseDotNet@2
inputs:
packageType: sdk
Expand Down
4 changes: 1 addition & 3 deletions src/Files.App/Actions/Git/GitPullAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public GitPullAction()

public Task ExecuteAsync()
{
GitHelpers.PullOrigin(_context.ShellPage!.InstanceViewModel.GitRepositoryPath);

return Task.CompletedTask;
return GitHelpers.PullOrigin(_context.ShellPage!.InstanceViewModel.GitRepositoryPath);
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
39 changes: 39 additions & 0 deletions src/Files.App/Actions/Git/GitPushAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Files.App.Commands;
using Files.App.Contexts;

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

public string Label { get; } = "Push".GetLocalizedResource();
yaira2 marked this conversation as resolved.
Show resolved Hide resolved

public string Description { get; } = "GitPushDescription".GetLocalizedResource();

public RichGlyph Glyph { get; } = new("\uE74A");

public bool IsExecutable =>
_context.CanExecuteGitAction;

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

_context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
{
return GitHelpers.PushToOrigin(
_context.ShellPage?.InstanceViewModel.GitRepositoryPath,
_context.ShellPage?.InstanceViewModel.GitBranchName);
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.CanExecuteGitAction))
OnPropertyChanged(nameof(IsExecutable));
}
}
}
42 changes: 42 additions & 0 deletions src/Files.App/Actions/Git/GitSyncAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Files.App.Commands;
using Files.App.Contexts;

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

public string Label { get; } = "GitSync".GetLocalizedResource();

public string Description { get; } = "GitSyncDescription".GetLocalizedResource();

public RichGlyph Glyph { get; } = new("\uEDAB");

public bool IsExecutable =>
_context.CanExecuteGitAction;

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

_context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
{
var instance = _context.ShellPage?.InstanceViewModel;

return GitHelpers.PullOrigin(instance?.GitRepositoryPath)
.ContinueWith(t => GitHelpers.PushToOrigin(
instance?.GitRepositoryPath,
instance?.GitBranchName));
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(IContentPageContext.CanExecuteGitAction))
OnPropertyChanged(nameof(IsExecutable));
}
}
}
2 changes: 2 additions & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,7 @@ public enum CommandCodes
// Git
GitFetch,
GitPull,
GitPush,
GitSync,
}
}
4 changes: 4 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand PlayAll => commands[CommandCodes.PlayAll];
public IRichCommand GitFetch => commands[CommandCodes.GitFetch];
public IRichCommand GitPull => commands[CommandCodes.GitPull];
public IRichCommand GitPush => commands[CommandCodes.GitPush];
public IRichCommand GitSync => commands[CommandCodes.GitSync];

public CommandManager()
{
Expand Down Expand Up @@ -312,6 +314,8 @@ public CommandManager()
[CommandCodes.PlayAll] = new PlayAllAction(),
[CommandCodes.GitFetch] = new GitFetchAction(),
[CommandCodes.GitPull] = new GitPullAction(),
[CommandCodes.GitPush] = new GitPushAction(),
[CommandCodes.GitSync] = new GitSyncAction(),
};

private void UpdateHotKeys()
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>

IRichCommand GitFetch { get; }
IRichCommand GitPull { get; }
IRichCommand GitPush { get; }
IRichCommand GitSync { get; }
}
}
23 changes: 16 additions & 7 deletions src/Files.App/Data/Models/DirectoryPropertiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ public bool ShowLocals
}
}

private string _PullInfo = "0";
public string PullInfo
private string _StatusInfo = "0 / 0";
public string StatusInfo
{
get => _PullInfo;
set => SetProperty(ref _PullInfo, value);
get => _StatusInfo;
set => SetProperty(ref _StatusInfo, value);
}

private string _ExtendedStatusInfo = string.Format("CommitsNumber".GetLocalizedResource(), 0);
public string ExtendedStatusInfo
{
get => _ExtendedStatusInfo;
set => SetProperty(ref _ExtendedStatusInfo, value);
}

public ObservableCollection<string> BranchesNames => _ShowLocals
Expand All @@ -92,9 +99,11 @@ public void UpdateGitInfo(bool isGitRepository, string? repositoryPath, BranchIt
_gitRepositoryPath = repositoryPath;
ShowLocals = true;

PullInfo = branches.Any()
? branches[0].BehindBy.ToString() ?? "0"
: "0";
var behind = branches.Any() ? branches[0].BehindBy ?? 0 : 0;
var ahead = branches.Any() ? branches[0].AheadBy ?? 0 : 0;

ExtendedStatusInfo = string.Format("GitSyncStatusExtendedInfo".GetLocalizedResource(), ahead, behind);
StatusInfo = $"{ahead} / {behind}";

if (isGitRepository)
{
Expand Down
95 changes: 95 additions & 0 deletions src/Files.App/Dialogs/GitHubLoginDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!-- Copyright (c) 2023 Files Community. Licensed under the MIT License. See the LICENSE. -->
<ContentDialog
x:Class="Files.App.Dialogs.GitHubLoginDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="{helpers:ResourceString Name=ConnectGitHub}"
CloseButtonCommand="{x:Bind ViewModel.CloseButtonCommand}"
CloseButtonStyle="{StaticResource AccentButtonStyle}"
CloseButtonText="{helpers:ResourceString Name=Close}"
CornerRadius="{StaticResource OverlayCornerRadius}"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
PrimaryButtonText="{helpers:ResourceString Name=OK}"
RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}"
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">

<ContentDialog.PrimaryButtonStyle>
<Style BasedOn="{StaticResource DefaultButtonStyle}" TargetType="Button">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel
HorizontalAlignment="Center"
Orientation="Horizontal"
Spacing="8">
<FontIcon FontSize="14" Glyph="&#xE8C8;" />
<TextBlock Text="{helpers:ResourceString Name=CopyCode}" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ContentDialog.PrimaryButtonStyle>

<ContentDialog.Resources>
<ResourceDictionary>
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
</ResourceDictionary>
</ContentDialog.Resources>

<Grid RowSpacing="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>

<StackPanel Width="360" Height="40">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to Border?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #12793

<!-- Subtitle -->
<TextBlock
ferrariofilippo marked this conversation as resolved.
Show resolved Hide resolved
x:Name="Subtitle"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{x:Bind ViewModel.Subtitle, Mode=OneWay}"
TextWrapping="WrapWholeWords" />
</StackPanel>

<StackPanel
x:Name="UserCodeContainer"
Grid.Row="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
x:Load="{x:Bind ViewModel.LoginConfirmed, Converter={StaticResource BoolNegationConverter}, Mode=OneWay}">
<HyperlinkButton
x:Name="LoginUrl"
Content="{x:Bind ViewModel.LoginUrl}"
NavigateUri="{x:Bind ViewModel.NavigateUri}" />
<TextBlock
Margin="12,8"
CharacterSpacing="150"
FontFamily="Cascadia Mono,Consolas,Segoe UI Variable"
FontSize="32"
FontWeight="Normal"
Text="{x:Bind ViewModel.UserCode}" />
</StackPanel>
<Border
x:Name="LoginSuccessBadge"
Grid.Row="1"
Width="70"
Height="70"
Margin="8"
x:Load="{x:Bind ViewModel.LoginConfirmed, Mode=OneWay}"
Background="#6ccb5f"
CornerRadius="35">
<SymbolIcon
Width="52"
Height="52"
Symbol="Accept" />
</Border>
</Grid>
</ContentDialog>
49 changes: 49 additions & 0 deletions src/Files.App/Dialogs/GitHubLoginDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml.Controls;
using Windows.ApplicationModel.DataTransfer;

namespace Files.App.Dialogs
{
public sealed partial class GitHubLoginDialog : ContentDialog, IDialog<GitHubLoginDialogViewModel>
{
public GitHubLoginDialogViewModel ViewModel
{
get => (GitHubLoginDialogViewModel)DataContext;
set
{
if (ViewModel is not null)
ViewModel.PropertyChanged -= ViewModel_PropertyChanged;

DataContext = value;
if (value is not null)
value.PropertyChanged += ViewModel_PropertyChanged;
}
}

public GitHubLoginDialog()
{
InitializeComponent();
}

public new async Task<DialogResult> ShowAsync() => (DialogResult)await base.ShowAsync();

private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
args.Cancel = true;

var data = new DataPackage();
data.SetText(ViewModel.UserCode);

Clipboard.SetContent(data);
Clipboard.Flush();
}

private void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(GitHubLoginDialogViewModel.LoginConfirmed) && ViewModel.LoginConfirmed)
PrimaryButtonText = null;
}
}
}
Loading