Skip to content

Commit

Permalink
All of the options now allow for the passing of an open git reference
Browse files Browse the repository at this point in the history
  • Loading branch information
madhephaestus committed Aug 19, 2023
1 parent 4b6089d commit d925ffe
Showing 1 changed file with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,10 @@ private static void deleteFolder(File folder) {
}

}

private static void loadFilesToList(ArrayList<String> f, File directory, String extnetion) {
loadFilesToList( f, directory, extnetion);
}
private static void loadFilesToList(ArrayList<String> f, File directory, String extnetion,Git ref) {
if (directory == null)
return;
for (final File fileEntry : directory.listFiles()) {
Expand All @@ -729,33 +731,37 @@ private static void loadFilesToList(ArrayList<String> f, File directory, String
continue;// skip this file as it fails the filter
// from the user
if (fileEntry.isDirectory()) {
loadFilesToList(f, fileEntry, extnetion);
loadFilesToList(f, fileEntry, extnetion,ref);
} else {

for (IScriptingLanguage l : langauges.values()) {
if (l.isSupportedFileExtenetion(fileEntry.getName())) {
f.add(findLocalPath(fileEntry));
f.add(findLocalPath(fileEntry,ref));
break;
}
}

}
}
}

public static ArrayList<String> filesInGit(String remote, String branch, String extnetion) throws Exception {
return filesInGit( remote, branch, extnetion,null);
}
public static ArrayList<String> filesInGit(String remote, String branch, String extnetion,Git ref) throws Exception {
ArrayList<String> f = new ArrayList<>();

// waitForLogin();
File gistDir = cloneRepo(remote, branch);
loadFilesToList(f, gistDir, extnetion);
loadFilesToList(f, gistDir, extnetion,ref);

return f;

}

public static ArrayList<String> filesInGit(String remote) throws Exception {
return filesInGit(remote, null, null);
return filesInGit(remote, null, null,null);
}
public static ArrayList<String> filesInGit(String remote,Git ref) throws Exception {
return filesInGit(remote, null, null,ref);
}

public static String getUserIdOfGist(String id) throws Exception {
Expand Down Expand Up @@ -859,7 +865,7 @@ public static void commit(String id, String branch, String FileName, String cont
if (!desired.getName().contentEquals("csgDatabase.json")) {
String[] gitID = ScriptingEngine.findGitTagFromFile(desired, gitRef);
String remoteURI = gitID[0];
ArrayList<String> f = ScriptingEngine.filesInGit(remoteURI);
ArrayList<String> f = ScriptingEngine.filesInGit(remoteURI,gitRef);
for (String s : f) {
if (s.contentEquals("csgDatabase.json")) {

Expand All @@ -869,7 +875,7 @@ public static void commit(String id, String branch, String FileName, String cont
CSGDatabase.saveDatabase();
@SuppressWarnings("resource")
String c = new Scanner(dbFile).useDelimiter("\\Z").next();
ScriptingEngine.commit(remoteURI, branch, s, c, "saving CSG database", false);
ScriptingEngine.commit(remoteURI, branch, s, c, "saving CSG database", false,gitRef);
}
}
}
Expand Down Expand Up @@ -1675,20 +1681,25 @@ public static File cloneRepo(String remoteURI, String branch) {
return gistDir;

}

public static String locateGitUrl(File f) throws IOException {
public static String locateGitUrl(File f) throws IOException{
return locateGitUrl(f,null);
}
public static String locateGitUrl(File f,Git ref) throws IOException {
File gitRepoFile = f;
while (gitRepoFile != null) {
gitRepoFile = gitRepoFile.getParentFile();
if (gitRepoFile != null)
if (new File(gitRepoFile.getAbsolutePath() + "/.git").exists()) {
// System.err.println("Fount git repo for file: "+gitRepoFile);
Repository localRepo = new FileRepository(gitRepoFile.getAbsoluteFile() + "/.git");
Git git = openGit(localRepo);
Git git=ref;
if(git==null)
git = openGit(localRepo);
String url = git.getRepository().getConfig().getString("remote", "origin", "url");
if (!url.endsWith(".git"))
url += ".git";
closeGit(git);
if(ref==null)
closeGit(git);
return url;
}
}
Expand Down Expand Up @@ -1774,6 +1785,8 @@ private static File fileFromGistID(String string, String string2)
}

public static String findLocalPath(File currentFile, Git git) {
if(git==null)
return findLocalPath(currentFile);
File dir = git.getRepository().getDirectory().getParentFile();

return dir.toURI().relativize(currentFile.toURI()).getPath();
Expand All @@ -1800,7 +1813,7 @@ public static String[] findGitTagFromFile(File currentFile) throws IOException {
}

public static String[] findGitTagFromFile(File currentFile, Git ref) throws IOException {
String string = locateGitUrl(currentFile);
String string = locateGitUrl(currentFile,ref);
Git git = ref;
if (git == null)
git = locateGit(currentFile);
Expand Down

0 comments on commit d925ffe

Please sign in to comment.