mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
Use new repository.getRefs()
instead of repository.state.refs
`repository.state.refs` is deprecated as part of https://github.com/microsoft/vscode/issues/170838
This commit is contained in:
parent
916a4c808d
commit
de50ff3619
@ -5,7 +5,7 @@ import FilePathUtils from '../utils/filePathUtils';
|
||||
import GitTextUtils from '../utils/gitTextUtils';
|
||||
import MagitUtils from '../utils/magitUtils';
|
||||
import MagitStatusView from '../views/magitStatusView';
|
||||
import { Status, Commit, RefType, Repository, Change } from '../typings/git';
|
||||
import { Status, Commit, RefType, Repository, Change, Ref } from '../typings/git';
|
||||
import { MagitBranch, MagitUpstreamRef } from '../models/magitBranch';
|
||||
import { gitRun, LogLevel } from '../utils/gitRawRunner';
|
||||
import * as Constants from '../common/constants';
|
||||
@ -132,16 +132,18 @@ export async function internalMagitStatus(repository: Repository): Promise<Magit
|
||||
|
||||
const HEAD = repository.state.HEAD as MagitBranch | undefined;
|
||||
|
||||
const refs = await getRefs(repository);
|
||||
|
||||
if (HEAD?.commit) {
|
||||
HEAD.commitDetails = await getCommit(repository, HEAD.commit);
|
||||
|
||||
HEAD.tag = repository.state.refs.find(r => HEAD?.commit === r.commit && r.type === RefType.Tag);
|
||||
HEAD.tag = refs.find(r => HEAD?.commit === r.commit && r.type === RefType.Tag);
|
||||
|
||||
try {
|
||||
if (HEAD.upstream?.remote) {
|
||||
const upstreamRemote = HEAD.upstream.remote;
|
||||
|
||||
const upstreamRemoteCommit = repository.state.refs.find(ref => ref.remote === upstreamRemote && ref.name === `${upstreamRemote}/${HEAD.upstream?.name}`)?.commit;
|
||||
const upstreamRemoteCommit = refs.find(ref => ref.remote === upstreamRemote && ref.name === `${upstreamRemote}/${HEAD.upstream?.name}`)?.commit;
|
||||
const upstreamRemoteCommitDetails = upstreamRemoteCommit ? getCommit(repository, upstreamRemoteCommit) : undefined;
|
||||
|
||||
const isRebaseUpstream = repository.getConfig(`branch.${HEAD.upstream.name}.rebase`);
|
||||
@ -157,7 +159,7 @@ export async function internalMagitStatus(repository: Repository): Promise<Magit
|
||||
HEAD.pushRemote = await pushRemoteStatus(repository);
|
||||
}
|
||||
|
||||
const remoteBranches = repository.state.refs.filter(ref => ref.type === RefType.RemoteHead);
|
||||
const remoteBranches = refs.filter(ref => ref.type === RefType.RemoteHead);
|
||||
|
||||
const remotes: MagitRemote[] = repository.state.remotes.map(remote => ({
|
||||
...remote,
|
||||
@ -181,10 +183,10 @@ export async function internalMagitStatus(repository: Repository): Promise<Magit
|
||||
mergingState: await mergingStateTask,
|
||||
cherryPickingState: await cherryPickingStateTask,
|
||||
revertingState: await revertingStateTask,
|
||||
branches: repository.state.refs.filter(ref => ref.type === RefType.Head),
|
||||
branches: refs.filter(ref => ref.type === RefType.Head),
|
||||
remotes,
|
||||
tags: repository.state.refs.filter(ref => ref.type === RefType.Tag),
|
||||
refs: repository.state.refs,
|
||||
tags: refs.filter(ref => ref.type === RefType.Tag),
|
||||
refs,
|
||||
submodules: repository.state.submodules,
|
||||
gitRepository: repository,
|
||||
forgeState: forgeState,
|
||||
@ -212,7 +214,8 @@ async function pushRemoteStatus(repository: Repository): Promise<MagitUpstreamRe
|
||||
const commitsAhead = await Promise.all(commitsAheadPushRemote.map(c => getCommit(repository, c)));
|
||||
const commitsBehind = await Promise.all(commitsBehindPushRemote.map(c => getCommit(repository, c)));
|
||||
|
||||
const pushRemoteCommit = repository.state.refs.find(ref => ref.remote === pushRemote && ref.name === `${pushRemote}/${HEAD.name}`)?.commit;
|
||||
const refs = await getRefs(repository);
|
||||
const pushRemoteCommit = refs.find(ref => ref.remote === pushRemote && ref.name === `${pushRemote}/${HEAD.name}`)?.commit;
|
||||
const pushRemoteCommitDetails = pushRemoteCommit ? getCommit(repository, pushRemoteCommit) : Promise.resolve(undefined);
|
||||
|
||||
return { remote: pushRemote, name: HEAD.name, commit: await pushRemoteCommitDetails, commitsAhead, commitsBehind };
|
||||
@ -306,7 +309,8 @@ async function rebasingStatus(repository: Repository, dotGitPath: string, logTas
|
||||
}
|
||||
|
||||
let ontoCommit = await getCommit(repository, await rebaseOntoPathFileTask!);
|
||||
let ontoBranch = repository.state.refs.find(ref => ref.commit === ontoCommit.hash && ref.type !== RefType.RemoteHead);
|
||||
const refs = await getRefs(repository);
|
||||
let ontoBranch = refs.find(ref => ref.commit === ontoCommit.hash && ref.type !== RefType.RemoteHead);
|
||||
|
||||
let onto = {
|
||||
name: ontoBranch?.name ?? GitTextUtils.shortHash(ontoCommit.hash),
|
||||
@ -403,4 +407,14 @@ async function getStashes(repository: Repository): Promise<Stash[]> {
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function getRefs(repository: Repository): Promise<Ref[]> {
|
||||
// `repository.getRefs` is not available on older versions and we should
|
||||
// just use `repository.state.refs` on those versions.
|
||||
if (typeof repository.getRefs !== 'function') {
|
||||
return repository.state.refs;
|
||||
}
|
||||
|
||||
return await repository.getRefs({});
|
||||
}
|
15
src/typings/git.d.ts
vendored
15
src/typings/git.d.ts
vendored
@ -103,6 +103,7 @@ export interface Change {
|
||||
|
||||
export interface RepositoryState {
|
||||
readonly HEAD: Branch | undefined;
|
||||
// @deprecated Use `Repository.getRefs()` instead.
|
||||
readonly refs: Ref[];
|
||||
readonly remotes: Remote[];
|
||||
readonly submodules: Submodule[];
|
||||
@ -147,11 +148,15 @@ export interface FetchOptions {
|
||||
depth?: number;
|
||||
}
|
||||
|
||||
export interface BranchQuery {
|
||||
readonly remote?: boolean;
|
||||
readonly pattern?: string;
|
||||
readonly count?: number;
|
||||
export interface RefQuery {
|
||||
readonly contains?: string;
|
||||
readonly count?: number;
|
||||
readonly pattern?: string;
|
||||
readonly sort?: 'alphabetically' | 'committerdate';
|
||||
}
|
||||
|
||||
export interface BranchQuery extends RefQuery {
|
||||
readonly remote?: boolean;
|
||||
}
|
||||
|
||||
export interface Repository {
|
||||
@ -197,6 +202,8 @@ export interface Repository {
|
||||
getBranches(query: BranchQuery): Promise<Ref[]>;
|
||||
setBranchUpstream(name: string, upstream: string): Promise<void>;
|
||||
|
||||
getRefs(query: RefQuery, /* cancellationToken?: CancellationToken */): Promise<Ref[]>;
|
||||
|
||||
getMergeBase(ref1: string, ref2: string): Promise<string>;
|
||||
|
||||
tag(name: string, upstream: string): Promise<void>;
|
||||
|
Loading…
Reference in New Issue
Block a user