[geany/geany-plugins] 7900eb: Merge pull request #1028 from nomadbyte/geanyvc/285-git-worktree

elextr git-noreply at geany.org
Tue Apr 26 03:16:31 UTC 2022


Branch:      refs/heads/master
Author:      elextr <elextr at gmail.com>
Committer:   GitHub <noreply at github.com>
Date:        Tue, 26 Apr 2022 03:16:31 UTC
Commit:      7900eb3b0f0b015e0999ad52a4ea834453bc805e
             https://github.com/geany/geany-plugins/commit/7900eb3b0f0b015e0999ad52a4ea834453bc805e

Log Message:
-----------
Merge pull request #1028 from nomadbyte/geanyvc/285-git-worktree

GeanyVC:(Git) Fallback to `git rev-parse` for getting the repo/worktree's top directory


Modified Paths:
--------------
    geanyvc/src/vc_git.c

Modified: geanyvc/src/vc_git.c
44 lines changed, 39 insertions(+), 5 deletions(-)
===================================================================
@@ -28,7 +28,37 @@ extern GeanyData *geany_data;
 static gchar *
 get_base_dir(const gchar * path)
 {
-	return find_subdir_path(path, ".git");
+	gchar *base_dir = NULL;
+	const gchar *argv[] = { "git", "rev-parse", "--show-toplevel", NULL };
+	gchar *dir = NULL;
+	gchar *filename = NULL;
+	gchar *std_out = NULL;
+	gchar *std_err = NULL;
+
+	base_dir = find_subdir_path(path, ".git");
+	if (base_dir) return base_dir;
+
+	if (g_file_test(path, G_FILE_TEST_IS_DIR))
+		dir = g_strdup(path);
+	else
+		dir = g_path_get_dirname(path);
+
+	execute_custom_command(dir, (const gchar **) argv, NULL, &std_out, &std_err,
+			       dir, NULL, NULL);
+	g_free(dir);
+	if (!std_out) return NULL;
+
+	/* trim the trailing newline */
+	sscanf(std_out, "%s\n", std_out);
+	dir = std_out;
+
+	filename = g_build_filename(dir, ".", NULL); /* in case of a trailing slash */
+	base_dir = g_path_get_dirname(filename);
+
+	g_free(filename);
+	g_free(dir);
+
+	return base_dir;
 }
 
 static gint
@@ -187,11 +217,15 @@ in_vc_git(const gchar * filename)
 	gboolean ret = FALSE;
 	gchar *std_output;
 
-	if (!find_dir(filename, ".git", TRUE))
-		return FALSE;
-
 	if (g_file_test(filename, G_FILE_TEST_IS_DIR))
+	{
+		gchar *base_dir = get_base_dir(filename);
+
+		if (!base_dir) return FALSE;
+
+		g_free(base_dir);
 		return TRUE;
+	}
 
 	dir = g_path_get_dirname(filename);
 	base_name = g_path_get_basename(filename);
@@ -254,7 +288,7 @@ get_commit_files_git(const gchar * file)
 	const gchar *argv[] = { "git", "status", NULL };
 	const gchar *env[] = { "PAGES=cat", NULL };
 	gchar *std_out = NULL;
-	gchar *base_dir = find_subdir_path(file, ".git");
+	gchar *base_dir = get_base_dir(file);
 	GSList *ret = NULL;
 
 	g_return_val_if_fail(base_dir, NULL);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list