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

Two problems on alias of git

From
Kana Natsuno <kana@whileimautomaton.net>
Date
May 5, 2009, 12:42 UTC
Message-ID
<op.utgiv92f6f2obg@i220-99-253-139.s27.a098.ap.plala.or.jp>
Hello.  I found 2 problems on alias of git.

The first one is that git crashes with the following situation. Without GIT_TRACE, everthing works well. But with GIT_TRACE=1, git crashes every time.

---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----
$ git remote show origin
* remote origin
  URL: git://repo.or.cz/git.git
  Remote branch merged with 'git pull' while on branch master
    master
  Tracked remote branches
    html
    maint
    man
    master
    next
    pu
    todo

$ git --version git version 1.6.2.rc0.90.g0753

$ git show HEAD | grep commit commit 3536ae331014c68a25c80b3fb530a19c8dee0f11

$ uname -a Darwin foobarbaz 9.6.1 Darwin Kernel Version 9.6.1: Sun Dec 21 19:45:33 PST 2008; root:xnu-1228.9.75~4/RELEASE_I386 i386 i386 MacBook5,2 Darwin

$ git config --get alias.l1 log --pretty=oneline

$ GIT_TRACE=1 git l1 trace: exec: 'git-l1' trace: run_command: 'git-l1' trace: exec 'git-l1' failed: No such file or directory [1] 41772 segmentation fault GIT_TRACE=1 git l1 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ----

The second one is that git doesn't expand a kind of aliases properly, especially with double quotation marks ("). I used the following alias recently to list the last 10 commits on HEAD:

[alias]
        lr = !git l1 | head | tac

Then I want to extend this alias to list the last N commits on a branch with "git lr 20", "git lr master", "git lr master 20", etc. So that I wrote the following definition (note that the actual definition is written in a single line, though the quoted definition is folded in multiple lines for readability):

[alias]
        lr = !$SHELL -c '
                n=10;
                1="${1:-$n}";
                if ! [ "${1##[0-9]*}" = "" ]; then
                  t="$1";
                  1="${2:-$n}";
                  2="$t";
                fi;
                git --no-pager l1 --reverse -"$1" "${2:-HEAD}"
              ' __dummy__
But it doesn't work because git expands as follows:

$ git config --get alias.lr !$SHELL -c '1=${1:-10}

Double quotation marks (") are removed and the aliased string is cut at a random position. I expect that the aliased string is passed to system() as-is, but git doesn't so. Why does git behave so? Is it a bug or an intentional behavior?

-- 
To Vim, or not to Vim.
http://whileimautomaton.net/
Next: Jakub Narebski
Message 1 of 7 in “Two problems on alias of git”
  1. Kana NatsunoMay 5, 2009
  2. Jakub NarebskiMay 5, 2009
  3. Kana NatsunoMay 5, 2009
  4. Jakub NarebskiMay 5, 2009
  5. Kana NatsunoMay 5, 2009
  6. Jakub NarebskiMay 5, 2009
  7. Jeff KingMay 8, 2009

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.