Compare commits
2 Commits
de595261e6
...
41333f06bc
| Author | SHA1 | Date | |
|---|---|---|---|
| 41333f06bc | |||
| fe292c02c9 |
12
how_to/Change_25.md
Normal file
12
how_to/Change_25.md
Normal file
@@ -0,0 +1,12 @@
|
||||
- cli: pass HEAD by default in argparse
|
||||
|
||||
First, make "@" be an alias for HEAD. (Implemented in `get_oid`)
|
||||
|
||||
Second, do a little refactoring in *cli.py*. Some commands accept an optional
|
||||
OID argument and if the argument isn't provided it defaults to HEAD. For example
|
||||
`git log` can get an OID to start logging from, but by default it logs all
|
||||
commits before HEAD.
|
||||
|
||||
Instead of having each command implement this logic, let's just make "@" (HEAD)
|
||||
be the default value for those commands. The relevant commands at this stage
|
||||
are `log` and `tag`. More will follow.
|
||||
@@ -130,6 +130,9 @@ def get_commit(oid):
|
||||
|
||||
|
||||
def get_oid(name):
|
||||
if name == "@":
|
||||
name = "HEAD"
|
||||
|
||||
# Name is ref
|
||||
refs_to_try = [
|
||||
f"{name}",
|
||||
|
||||
@@ -45,7 +45,7 @@ def parse_args():
|
||||
|
||||
log_parser = commands.add_parser("log")
|
||||
log_parser.set_defaults(func=log)
|
||||
log_parser.add_argument("oid", type=oid, nargs="?")
|
||||
log_parser.add_argument("oid", default="@", type=oid, nargs="?")
|
||||
|
||||
checkout_parser = commands.add_parser("checkout")
|
||||
checkout_parser.set_defaults(func=checkout)
|
||||
@@ -54,7 +54,7 @@ def parse_args():
|
||||
tag_parser = commands.add_parser("tag")
|
||||
tag_parser.set_defaults(func=tag)
|
||||
tag_parser.add_argument("name")
|
||||
tag_parser.add_argument("oid", type=oid, nargs="?")
|
||||
tag_parser.add_argument("oid", default="@", type=oid, nargs="?")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
@@ -87,7 +87,7 @@ def commit(args):
|
||||
|
||||
|
||||
def log(args):
|
||||
oid = args.oid or data.get_ref("HEAD")
|
||||
oid = args.oid
|
||||
while oid:
|
||||
commit = base.get_commit(oid)
|
||||
|
||||
@@ -103,5 +103,4 @@ def checkout(args):
|
||||
|
||||
|
||||
def tag(args):
|
||||
oid = args.oid or data.get_ref("HEAD")
|
||||
base.create_tag(args.name, oid)
|
||||
base.create_tag(args.name, args.oid)
|
||||
|
||||
Reference in New Issue
Block a user