88from pathlib import Path
99from . import __version__ , __app_name__ , logger
1010
11+
1112def import_asyncio ():
1213 import asyncio
14+
1315 try :
1416 import uvloop
17+
1518 asyncio .set_event_loop_policy (uvloop .EventLoopPolicy ())
1619 except ImportError :
1720 pass
1821 return asyncio
1922
2023
2124# --------------------------------------------------
25+ # git_pp.py
2226def get_args ():
2327 """Get command-line arguments"""
2428
29+ epilog_text = """
30+ Examples:
31+ You can run this program with either `git-pp` or `git pp`.
32+
33+ # Check status, stage changes, and commit with a timestamp message in the current directory
34+ git pp
35+
36+ # Do the same as above, but also push to all remotes
37+ git pp -p
38+
39+ # Just push the current branch to all remotes without creating a new commit
40+ git pp -po
41+
42+ # Check status, stage changes, and commit with a custom message
43+ git pp -m "feat: add new feature"
44+
45+ # Perform the pre-pull and push operation on multiple directories
46+ git pp -p path/to/repo1 path/to/repo2
47+
48+ # Push only specific remotes (works with -p or -po)
49+ git pp -p -r origin upstream
50+ git pp -po -r origin
51+
52+ # Push a specific branch (works with -p or -po)
53+ git pp -po -b main
54+
55+ # Force push (works with -p or -po)
56+ git pp -po -f
57+
58+ # Set a timeout for push operations (e.g., 60 seconds, works with -p or -po)
59+ git pp -p -t 60
60+
61+ For more details, visit: https://github.com/tddschn/git-pp
62+
63+ This is an old project, created for self-use only (I still use it daily), to replace some bash scripts and learn asyncio.
64+ """
65+
2566 parser = argparse .ArgumentParser (
2667 prog = __app_name__ ,
27- description = 'Git utility for auto-committing and concurrent pushing' ,
28- formatter_class = argparse .ArgumentDefaultsHelpFormatter )
29-
30- parser .add_argument ('dirs' ,
31- metavar = 'DIRS' ,
32- nargs = '*' ,
33- help = 'Dirs to operate on' ,
34- type = Path ,
35- default = ['.' ])
36-
37- parser .add_argument ('-m' ,
38- '--commit-message' ,
39- help = 'commit message' ,
40- metavar = 'COMMIT_MESSAGE' ,
41- type = str ,
42- default = None )
43-
44- # parser.add_argument('-i',
45- # '--int',
46- # help='A named integer argument',
47- # metavar='int',
48- # type=int,
49- # default=0)
50-
51- parser .add_argument ('-v' ,
52- '--version' ,
53- action = 'version' ,
54- version = f'%(prog)s { __version__ } ' )
55-
56- parser .add_argument ('-so' ,
57- '--status-only' ,
58- help = 'Prints status only' ,
59- action = 'store_true' )
60-
61- parser .add_argument ('-p' ,
62- '--push' ,
63- help = 'Push to all remotes' ,
64- action = 'store_true' )
65-
66- parser .add_argument ('-po' ,
67- '--push-only' ,
68- help = 'Push to all remotes, without pre_pull' ,
69- action = 'store_true' )
70-
71- parser .add_argument ('-r' ,
72- '--remote' ,
73- help = 'Remote name' ,
74- metavar = 'REMOTE' ,
75- type = str ,
76- default = None ,
77- nargs = '+' )
78-
79- parser .add_argument ('-b' ,
80- '--branch' ,
81- help = 'Branch name' ,
82- metavar = 'BRANCH' ,
83- type = str ,
84- default = None )
85-
86- parser .add_argument ('-f' ,
87- '--force' ,
88- help = 'Force push' ,
89- action = 'store_true' )
90-
91- parser .add_argument ('-t' ,
92- '--timeout' ,
93- help = 'Timeout for a single push' ,
94- metavar = 'TIMEOUT' ,
95- type = float ,
96- default = None )
68+ description = "Git utility for auto-committing and concurrent pushing" ,
69+ formatter_class = argparse .RawDescriptionHelpFormatter , # Use RawDescriptionHelpFormatter to preserve epilog formatting
70+ epilog = epilog_text , # Add the epilog
71+ )
72+
73+ parser .add_argument (
74+ "dirs" ,
75+ metavar = "DIRS" ,
76+ nargs = "*" ,
77+ help = "Dirs to operate on (default: current directory)" ,
78+ type = Path ,
79+ default = ["." ],
80+ )
81+
82+ parser .add_argument (
83+ "-m" ,
84+ "--commit-message" ,
85+ help = "Commit message (default: ISO8601 timestamp)" ,
86+ metavar = "COMMIT_MESSAGE" ,
87+ type = str ,
88+ default = None ,
89+ )
90+
91+ parser .add_argument (
92+ "-v" , "--version" , action = "version" , version = f"%(prog)s { __version__ } "
93+ )
94+
95+ parser .add_argument (
96+ "-so" ,
97+ "--status-only" ,
98+ help = "Prints status only, stages changes, but does not commit" ,
99+ action = "store_true" ,
100+ )
101+
102+ parser .add_argument (
103+ "-p" ,
104+ "--push" ,
105+ help = "Stage, commit (if needed), and push to specified/all remotes" ,
106+ action = "store_true" ,
107+ )
108+
109+ parser .add_argument (
110+ "-po" ,
111+ "--no-create-commit" ,
112+ "--push-only" ,
113+ dest = "push_only" ,
114+ help = "Push current state to specified/all remotes, without staging or committing first" ,
115+ action = "store_true" ,
116+ )
117+
118+ parser .add_argument (
119+ "-r" ,
120+ "--remote" ,
121+ help = "Specify remote name(s) to push to (default: all remotes)" ,
122+ metavar = "REMOTE" ,
123+ type = str ,
124+ default = None ,
125+ nargs = "+" ,
126+ )
127+
128+ parser .add_argument (
129+ "-b" ,
130+ "--branch" ,
131+ help = "Specify branch name to push (default: current branch)" ,
132+ metavar = "BRANCH" ,
133+ type = str ,
134+ default = None ,
135+ )
136+
137+ parser .add_argument (
138+ "-f" , "--force" , help = "Force push (`git push --force`)" , action = "store_true"
139+ )
140+
141+ parser .add_argument (
142+ "-t" ,
143+ "--timeout" ,
144+ help = "Timeout in seconds for each push operation" ,
145+ metavar = "TIMEOUT" ,
146+ type = float ,
147+ default = None ,
148+ )
97149
98150 return parser .parse_args ()
99151
@@ -115,7 +167,7 @@ async def main(args):
115167 from .git_push_to_all_remotes import git_push_to_all_remote_C
116168
117169 if push and push_only :
118- sys .exit (' Error: -po and -p are mutually exclusive' )
170+ sys .exit (" Error: -po and -p are mutually exclusive" )
119171 elif push :
120172 await git_pre_pull_and_push_to_all_remote_C (
121173 dirs = dirs ,
@@ -124,26 +176,27 @@ async def main(args):
124176 remotes = remotes ,
125177 branch = branch ,
126178 force = force ,
127- timeout = timeout )
179+ timeout = timeout ,
180+ )
128181 elif push_only :
129- await git_push_to_all_remote_C (dirs = dirs ,
130- remotes = remotes ,
131- branch = branch ,
132- force = force ,
133- timeout = timeout )
182+ await git_push_to_all_remote_C (
183+ dirs = dirs , remotes = remotes , branch = branch , force = force , timeout = timeout
184+ )
134185 else :
135- await git_pre_pull (dirs [0 ] if dirs else '.' ,
136- commit_message = commit_message ,
137- status_only = status_only )
186+ await git_pre_pull (
187+ dirs [0 ] if dirs else "." ,
188+ commit_message = commit_message ,
189+ status_only = status_only ,
190+ )
138191
139192
140193def main_sync ():
141- logger .info (' getting args' )
194+ logger .info (" getting args" )
142195 args = get_args ()
143- logger .info (' importing asyncio' )
196+ logger .info (" importing asyncio" )
144197 asyncio = import_asyncio ()
145198 asyncio .run (main (args ))
146199
147200
148- if __name__ == ' __main__' :
201+ if __name__ == " __main__" :
149202 main_sync ()
0 commit comments