-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
173 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
options="" | ||
|
||
usage() { | ||
cat <<HERE | ||
usage: git alias # list all aliases | ||
or: git alias <search-pattern> # show aliases matching pattern | ||
or: git alias <alias-name> <command> # alias a command | ||
usage: git alias [options] # list all aliases | ||
or: git alias [options] <search-pattern> # show aliases matching pattern | ||
or: git alias [options] <alias-name> <command> # alias a command | ||
options: | ||
--global | ||
For writing options: write to global ~/.gitconfig file | ||
For reading options: read only from global ~/.gitconfig | ||
--local | ||
For writing options: write to the repository .git/config file | ||
For reading options: read only from the repository .git/config | ||
HERE | ||
} | ||
|
||
if [[ "$1" == "--local" || "$1" == "--global" ]]; then | ||
options=$1 | ||
shift | ||
fi | ||
|
||
case $# in | ||
0) git config --get-regexp 'alias.*' | sed 's/^alias\.//' | sed 's/[ ]/ = /' | sort ;; | ||
1) git alias | grep -e "$1" ;; | ||
2) git config --global alias."$1" "$2" ;; | ||
0) git config $options --get-regexp 'alias.*' | sed 's/^alias\.//' | sed 's/[ ]/ = /' | sort ;; | ||
1) git config $options --get-regexp 'alias.*' | sed 's/^alias\.//' | sed 's/[ ]/ = /' | sort | grep -e "$1" ;; | ||
2) git config $options alias."$1" "$2" ;; | ||
*) >&2 echo "error: too many arguments." && usage && exit 1 ;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,109 @@ | ||
.\" generated with Ronn-NG/v0.9.1 | ||
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1 | ||
.TH "GIT\-ALIAS" "1" "August 2021" "" "Git Extras" | ||
.\" generated with Ronn/v0.7.3 | ||
.\" http://github.com/rtomayko/ronn/tree/0.7.3 | ||
. | ||
.TH "GIT\-ALIAS" "1" "September 2023" "" "Git Extras" | ||
. | ||
.SH "NAME" | ||
\fBgit\-alias\fR \- Define, search and show aliases | ||
. | ||
.SH "SYNOPSIS" | ||
\fBgit\-alias\fR | ||
. | ||
.br | ||
\fBgit\-alias\fR <search\-pattern> | ||
. | ||
.br | ||
\fBgit\-alias\fR <alias\-name> <command> | ||
. | ||
.br | ||
\fBgit\-alias\fR \-\-global <alias\-name> <command> | ||
. | ||
.br | ||
\fBgit\-alias\fR \-\-local <alias\-name> <command> | ||
. | ||
.SH "DESCRIPTION" | ||
List all aliases, show one alias, or set one (global) alias\. | ||
. | ||
.SH "OPTIONS" | ||
<\-\-global> | ||
. | ||
.P | ||
write and read the config from ~/\.gitconfig file only\. | ||
. | ||
.P | ||
<\-\-local> | ||
. | ||
.P | ||
write and read the config from \.git/config file only\. | ||
. | ||
.P | ||
<search\-pattern> | ||
. | ||
.P | ||
The pattern used to search aliases\. | ||
. | ||
.P | ||
<alias\-name> | ||
. | ||
.P | ||
The name of the alias to create\. | ||
. | ||
.P | ||
<command> | ||
. | ||
.P | ||
The command for which you are creating an alias\. | ||
. | ||
.SH "EXAMPLES" | ||
Defining a new alias: | ||
. | ||
.IP "" 4 | ||
. | ||
.nf | ||
|
||
$ git alias last "cat\-file commit HEAD" | ||
. | ||
.fi | ||
. | ||
.IP "" 0 | ||
. | ||
.P | ||
Providing only one argument, \fBgit\-alias\fR searches for aliases matching the given value: | ||
. | ||
.IP "" 4 | ||
. | ||
.nf | ||
|
||
$ git alias ^la | ||
last = cat\-file commit HEAD | ||
. | ||
.fi | ||
. | ||
.IP "" 0 | ||
. | ||
.P | ||
\fBgit\-alias\fR will show all aliases if no argument is given: | ||
. | ||
.IP "" 4 | ||
. | ||
.nf | ||
|
||
$ git alias | ||
s = status | ||
amend = commit \-\-amend | ||
rank = shortlog \-sn \-\-no\-merges | ||
whatis = show \-s \-\-pretty=\'tformat:%h (%s, %ad)\' \-\-date=short | ||
whois = !sh \-c \'git log \-i \-1 \-\-pretty="format:%an <%ae> | ||
. | ||
.fi | ||
. | ||
.IP "" 0 | ||
. | ||
.SH "AUTHOR" | ||
Written by Jonhnny Weslley <\fIjw@jonhnnyweslley\.net\fR> | ||
. | ||
.SH "REPORTING BUGS" | ||
<\fIhttps://github\.com/tj/git\-extras/issues\fR> | ||
. | ||
.SH "SEE ALSO" | ||
<\fIhttps://github\.com/tj/git\-extras\fR> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
class TestGitAlias: | ||
def test_init(self, temp_repo): | ||
git = temp_repo.get_repo_git() | ||
git.config("--global", "alias.globalalias", "status") | ||
git.config("--global", "alias.x", "status") | ||
git.config("--local", "alias.localalias", "status") | ||
git.config("--local", "alias.y", "status") | ||
|
||
def test_list_all(self, temp_repo): | ||
actual = temp_repo.invoke_extras_command("alias") | ||
actual = actual.stdout.decode() | ||
assert "globalalias = status" in actual | ||
assert "x = status" in actual | ||
assert "localalias = status" in actual | ||
assert "y = status" in actual | ||
|
||
def test_list_all_globally(self, temp_repo): | ||
actual = temp_repo.invoke_extras_command("alias", "--global") | ||
actual = actual.stdout.decode() | ||
assert "globalalias = status" in actual | ||
|
||
def test_list_all_locally(self, temp_repo): | ||
actual = temp_repo.invoke_extras_command("alias", "--local") | ||
actual = actual.stdout.decode() | ||
assert "localalias = status" in actual | ||
|
||
def test_search_globally(self, temp_repo): | ||
actual = temp_repo.invoke_extras_command("alias", "--global", "global") | ||
actual = actual.stdout.decode() | ||
assert "globalalias = status" in actual | ||
actual = temp_repo.invoke_extras_command("alias", "--global", "local") | ||
actual = actual.stdout.decode() | ||
assert "" == actual | ||
|
||
def test_search_locally(self, temp_repo): | ||
actual = temp_repo.invoke_extras_command("alias", "--local", "local") | ||
actual = actual.stdout.decode() | ||
assert "localalias = status" in actual | ||
actual = temp_repo.invoke_extras_command("alias", "--local", "global") | ||
actual = actual.stdout.decode() | ||
assert "" == actual | ||
|
||
def test_get_alias_globally_and_defaultly(self, temp_repo): | ||
actual = temp_repo.invoke_extras_command("alias", "globalalias") | ||
actual = actual.stdout.decode() | ||
assert "globalalias = status" in actual | ||
|
||
def test_set_alias_globally_and_defaultly(self, temp_repo): | ||
temp_repo.invoke_extras_command("alias", "globalalias", "diff") | ||
actual = temp_repo.invoke_extras_command("alias") | ||
actual = actual.stdout.decode() | ||
assert "globalalias = diff" in actual | ||
|
||
def test_get_alias_locally(self, temp_repo): | ||
actual = temp_repo.invoke_extras_command("alias", "--local", "localalias") | ||
actual = actual.stdout.decode() | ||
assert "localalias = status" in actual | ||
|
||
def test_set_alias_locally(self, temp_repo): | ||
temp_repo.invoke_extras_command("alias", "--local", "localalias", "diff") | ||
actual = temp_repo.invoke_extras_command("alias") | ||
actual = actual.stdout.decode() | ||
assert "localalias = diff" in actual | ||
|
||
def test_teardown(self, temp_repo): | ||
git = temp_repo.get_repo_git() | ||
git.config("--global", "--unset", "alias.globalalias") | ||
git.config("--global", "--unset", "alias.x") | ||
git.config("--local", "--unset", "alias.localalias") | ||
git.config("--local", "--unset", "alias.y") |