Skip to content

Commit 3b1a54d

Browse files
committed
refactor: use git update-ref $LOCAL_BRANCH $REMOTE_BRANCH instead of git fetch $REMOTE $LOCAL_BRANCH $REMOTE_BRANCH to fast-forward local branch without checkout it first.
1 parent 00a2ec5 commit 3b1a54d

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/Commands/Fetch.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ public Fetch(string repo, string remote, bool prune, bool noTags, Action<string>
2424
Args += remote;
2525
}
2626

27-
public Fetch(string repo, string remote, string localBranch, string remoteBranch, Action<string> outputHandler)
28-
{
29-
_outputHandler = outputHandler;
30-
WorkingDirectory = repo;
31-
Context = repo;
32-
TraitErrorAsOutput = true;
33-
SSHKey = new Config(repo).Get($"remote.{remote}.sshkey");
34-
Args = $"fetch --progress --verbose {remote} {remoteBranch}:{localBranch}";
35-
}
36-
3727
protected override void OnReadline(string line)
3828
{
3929
_outputHandler?.Invoke(line);

src/Commands/UpdateRef.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
namespace SourceGit.Commands
4+
{
5+
public class UpdateRef : Command
6+
{
7+
public UpdateRef(string repo, string refName, string toRevision, Action<string> outputHandler)
8+
{
9+
_outputHandler = outputHandler;
10+
11+
WorkingDirectory = repo;
12+
Context = repo;
13+
Args = $"update-ref {refName} {toRevision}";
14+
}
15+
16+
protected override void OnReadline(string line)
17+
{
18+
_outputHandler?.Invoke(line);
19+
}
20+
21+
private Action<string> _outputHandler;
22+
}
23+
}

src/ViewModels/FastForwardWithoutCheckout.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override Task<bool> Sure()
3131

3232
return Task.Run(() =>
3333
{
34-
new Commands.Fetch(_repo.FullPath, To.Remote, Local.Name, To.Name, SetProgressDescription).Exec();
34+
new Commands.UpdateRef(_repo.FullPath, Local.FullName, To.FullName, SetProgressDescription).Exec();
3535
CallUIThread(() => _repo.SetWatcherEnabled(true));
3636
return true;
3737
});

0 commit comments

Comments
 (0)