Skip to content

Commit

Permalink
GeanyVC:(Git) Fallback to git rev-parse for getting the repo/worktr…
Browse files Browse the repository at this point in the history
…ee's top directory

An example setup for worktree:

```
mkdir r1
cd r1

git init
git config user.name testuser
git config user.email testuser@
echo "f1" >> f1
git add f1
git commit -a -m "added f1"

git worktree add ../w1 -b work1
echo "f1:r1" >> f1
git status

cd ../w1
git status
echo "f2" >> f2
git add f2
git commit -a -m "added f2"
echo "f1:w1" >> f1
git status
```

All VC actions should be available for all files in each worktree.
  • Loading branch information
nomadbyte committed Apr 26, 2022
1 parent fcc7787 commit 187dfc2
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions geanyvc/src/vc_git.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 187dfc2

Please sign in to comment.