git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] parse-options: expand $HOME on filename options

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 14, 2018, 10:51 UTC
Message-ID
<20180214105149.28896-1-pclouds@gmail.com>
In-Reply-To
<20180214101019.gaenosifgq3wx2nm@NUC.localdomain>

When you specify "--path ~/foo", the shell will automatically expand ~/foo to $HOME/foo before it's passed to git. The expansion is not done on "--path=~/foo". An experienced user sees the difference but it could still be confusing for others (especially when tab-completion still works on --path=~/foo).

Support $HOME expansion for all filename options. There are about seven of them.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index d265a756b5..c33f14c74e 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -38,10 +38,13 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
 
 static void fix_filename(const char *prefix, const char **file)
 {
-	if (!file || !*file || !prefix || is_absolute_path(*file)
-	    || !strcmp("-", *file))
+	if (!file || !*file || is_absolute_path(*file) ||
+	    !strcmp("-", *file))
 		return;
-	*file = prefix_filename(prefix, *file);
+	if (**file == '~')
+		*file = expand_user_path(*file, 0);
+	else if (prefix)
+		*file = prefix_filename(prefix, *file);
 }
 
 static int opt_command_mode_error(const struct option *opt,
-- 
2.16.1.435.g8f24da2e1a
Previous: Doron BeharNext: Nguyễn Thái Ngọc Duy
Message 2 of 11 in “[BUG] git init doesn't respect `--template` like configuration variable init.templateDir and $GIT_TEMPLATE_DIR”
  1. Doron BeharFeb 14, 2018
  2. 1/2 parse-options: expand $HOME on filename optionsNguyễn Thái Ngọc Duy, Feb 14, 2018
  3. 2/2 init-db: change --template type to OPTION_FILENAMENguyễn Thái Ngọc Duy, Feb 14, 2018
  4. Jeff KingFeb 14, 2018
  5. Jeff KingFeb 14, 2018
  6. Junio C HamanoFeb 14, 2018
  7. Ævar Arnfjörð BjarmasonFeb 14, 2018
  8. Junio C HamanoFeb 15, 2018
  9. Duy NguyenFeb 22, 2018
  10. Ævar Arnfjörð BjarmasonFeb 22, 2018
  11. Duy NguyenFeb 23, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.