mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] check if repository is a shallow clone
This commit is contained in:
@@ -38,6 +38,7 @@ public class GitRepoInfo {
|
||||
@NotNull private final Set<GitBranchTrackInfo> myBranchTrackInfos;
|
||||
@NotNull private final Collection<GitSubmoduleInfo> mySubmodules;
|
||||
@NotNull private final GitHooksInfo myHooksInfo;
|
||||
private final boolean myIsShallow;
|
||||
|
||||
public GitRepoInfo(@Nullable GitLocalBranch currentBranch,
|
||||
@Nullable String currentRevision,
|
||||
@@ -47,7 +48,8 @@ public class GitRepoInfo {
|
||||
@NotNull Map<GitRemoteBranch, Hash> remoteBranches,
|
||||
@NotNull Collection<GitBranchTrackInfo> branchTrackInfos,
|
||||
@NotNull Collection<GitSubmoduleInfo> submodules,
|
||||
@NotNull GitHooksInfo hooksInfo) {
|
||||
@NotNull GitHooksInfo hooksInfo,
|
||||
boolean isShallow) {
|
||||
myCurrentBranch = currentBranch;
|
||||
myCurrentRevision = currentRevision;
|
||||
myState = state;
|
||||
@@ -57,6 +59,7 @@ public class GitRepoInfo {
|
||||
myBranchTrackInfos = new LinkedHashSet<>(branchTrackInfos);
|
||||
mySubmodules = submodules;
|
||||
myHooksInfo = hooksInfo;
|
||||
myIsShallow = isShallow;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -110,6 +113,10 @@ public class GitRepoInfo {
|
||||
return myHooksInfo;
|
||||
}
|
||||
|
||||
public boolean isShallow() {
|
||||
return myIsShallow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@@ -126,6 +133,7 @@ public class GitRepoInfo {
|
||||
if (!areEqual(myRemoteBranches, info.myRemoteBranches)) return false;
|
||||
if (!mySubmodules.equals(info.mySubmodules)) return false;
|
||||
if (!myHooksInfo.equals(info.myHooksInfo)) return false;
|
||||
if (myIsShallow != info.myIsShallow) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -141,6 +149,7 @@ public class GitRepoInfo {
|
||||
result = 31 * result + myBranchTrackInfos.hashCode();
|
||||
result = 31 * result + mySubmodules.hashCode();
|
||||
result = 31 * result + myHooksInfo.hashCode();
|
||||
result = 31 * result + (myIsShallow ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -178,5 +187,4 @@ public class GitRepoInfo {
|
||||
return b1.getKey().getName().equals(b2.getKey().getName()) && b1.getValue().equals(b2.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public class GitRepositoryFiles {
|
||||
private static final String HOOKS = "hooks";
|
||||
private static final String PRE_COMMIT_HOOK = "pre-commit";
|
||||
private static final String PRE_PUSH_HOOK = "pre-push";
|
||||
private static final String SHALLOW = "shallow";
|
||||
|
||||
private final VirtualFile myMainDir;
|
||||
private final VirtualFile myWorktreeDir;
|
||||
@@ -81,6 +82,7 @@ public class GitRepositoryFiles {
|
||||
private final String myInfoDirPath;
|
||||
private final String myExcludePath;
|
||||
private final String myHooksDirPath;
|
||||
private final String myShallow;
|
||||
|
||||
private GitRepositoryFiles(@NotNull VirtualFile mainDir, @NotNull VirtualFile worktreeDir) {
|
||||
myMainDir = mainDir;
|
||||
@@ -96,6 +98,7 @@ public class GitRepositoryFiles {
|
||||
myInfoDirPath = mainPath + slash(INFO);
|
||||
myExcludePath = mainPath + slash(INFO_EXCLUDE);
|
||||
myHooksDirPath = mainPath + slash(HOOKS);
|
||||
myShallow = mainPath + slash(SHALLOW);
|
||||
|
||||
String worktreePath = myWorktreeDir.getPath();
|
||||
myHeadFilePath = worktreePath + slash(HEAD);
|
||||
@@ -226,6 +229,11 @@ public class GitRepositoryFiles {
|
||||
return file(myHooksDirPath + slash(PRE_PUSH_HOOK));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public File getShallowFile() {
|
||||
return file(myShallow);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File file(@NotNull String filePath) {
|
||||
return new File(FileUtil.toSystemDependentName(filePath));
|
||||
|
||||
@@ -210,12 +210,13 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
GitConfig config = GitConfig.read(configFile);
|
||||
Collection<GitRemote> remotes = config.parseRemotes();
|
||||
GitBranchState state = myReader.readState(remotes);
|
||||
boolean isShallow = myReader.hasShallowCommits();
|
||||
Collection<GitBranchTrackInfo> trackInfos = config.parseTrackInfos(state.getLocalBranches().keySet(), state.getRemoteBranches().keySet());
|
||||
GitHooksInfo hooksInfo = myReader.readHooksInfo();
|
||||
Collection<GitSubmoduleInfo> submodules = new GitModulesFileReader().read(getSubmoduleFile());
|
||||
sw.report();
|
||||
return new GitRepoInfo(state.getCurrentBranch(), state.getCurrentRevision(), state.getState(), remotes,
|
||||
state.getLocalBranches(), state.getRemoteBranches(), trackInfos, submodules, hooksInfo);
|
||||
state.getLocalBranches(), state.getRemoteBranches(), trackInfos, submodules, hooksInfo, isShallow);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -103,6 +103,15 @@ class GitRepositoryReader {
|
||||
return file.exists() && file.canExecute();
|
||||
}
|
||||
|
||||
boolean hasShallowCommits() {
|
||||
File shallowFile = myGitFiles.getShallowFile();
|
||||
if (!shallowFile.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return shallowFile.length() > 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getCurrentRevision(@NotNull HeadInfo headInfo, @Nullable Hash currentBranchHash) {
|
||||
String currentRevision;
|
||||
|
||||
Reference in New Issue
Block a user