Skip to contentSkip to conversation

Support for configurable git command aliases (v3)

PATCH In review Petr Baudis 2 participants 3 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support for configurable git command aliases (v3)

This patch adds support for configurable aliases for git commands - "alias.WHATEVER = which ever" will kick in when you do "git WHATEVER" and substitute WHATEVER with "which ever" (splitted to arguments at whitespaces).

The second version does all the work in handle_aliases() which was inspired by Johannes Schindelin's patch.

The third version does not expand aliases when called as 'git-something' or when the $GIT_NO_ALIASES environment variable is set; that is now done in git-sh-setup.sh. The documentation has been slightly expanded.

---

 Documentation/config.txt |   12 +++++++++
 Documentation/git.txt    |    3 ++
 git-sh-setup.sh          |    2 +
 git.c                    |   64 ++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 78 insertions(+), 3 deletions(-)
Documentation/config.txt +12 -0
index c861c6c..071ff4e 100644
@@ -91,6 +91,18 @@ core.warnAmbiguousRefs::
 	If true, git will warn you if the ref name you passed it is ambiguous
 	and might match multiple refs in the .git/refs/ tree. True by default.
 
+alias.*::
+	Command aliases for the gitlink:git[1] command wrapper - e.g.
+	after defining "alias.last = cat-file commit HEAD", the invocation
+	"git last" is equivalent to "git cat-file commit HEAD". You can
+	override even existing command names with aliases (you can use that
+	to define some default set of parameters for some command). However,
+	there is only a single level of alias expansion - the alias definition
+	is not searched for aliases anymore. Alias checking is disabled when
+	the "$GIT_NO_ALIASES" environment variable is set - you should
+	definitely do that if you call commands by the 'git' wrapper in your
+	scripts.
+
 apply.whitespace::
 	Tells `git-apply` how to handle whitespaces, in the same way
 	as the '--whitespace' option. See gitlink:git-apply[1].
Documentation/git.txt +3 -0
index 24ca55d..e474bdf 100644
@@ -21,6 +21,9 @@ link:everyday.html[Everyday Git] for a u
 "man git-commandname" for documentation of each command.  CVS users may
 also want to read link:cvs-migration.html[CVS migration].
 
+The COMMAND is either a name of a Git command (see below) or an alias
+as defined in the configuration file (see gitlink:git-repo-config[1]).
+
 OPTIONS
 -------
 --version::
git-sh-setup.sh +2 -0
index d15747f..c56ae8c 100755
@@ -49,3 +49,5 @@ then
 else
 	GIT_DIR=$(git-rev-parse --git-dir) || exit
 fi
+
+export GIT_NO_ALIASES=1
git.c +61 -3

93 lines not on this page · raw message

#1 lore raw

Dear diary, on Wed, Jun 07, 2006 at 02:16:38AM CEST, I got a letter where Petr Baudis <[email protected]> said that...

Quoted 5 lines

This patch adds support for configurable aliases for git commands - "alias.WHATEVER = which ever" will kick in when you do "git WHATEVER" and substitute WHATEVER with "which ever" (splitted to arguments at whitespaces).

Quoted 8 lines

The second version does all the work in handle_aliases() which was inspired by Johannes Schindelin's patch.

The third version does not expand aliases when called as 'git-something' or when the $GIT_NO_ALIASES environment variable is set; that is now done in git-sh-setup.sh. The documentation has been slightly expanded.

So, I chose the approach suggested by Linus, but I do not have a strong preference and if Junio still wants, we can rather just disallow aliases with the same name as builtins - I just think that it *might* be practical to add some default options to the commands without relearning your typing habits.

Signature · 3 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
A person is just about as big as the things that make them angry.
#2 lore raw
In reply to Petr Baudis

I've already swallowed Johannes's patch that also takes good parts from your patch (most importantly, the part to call setup_git_directory_gently() so that things can work from a subdirectory and still find the config) in "next", and I am hoping to push it out by end of (my) tomorrow. So I'd appreciate any improvements (including docs perhaps) on top of that instead.