Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qutil
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
qutech
qutil
Commits
2ce50009
Commit
2ce50009
authored
1 year ago
by
Simon Sebastian Humpohl
Browse files
Options
Downloads
Patches
Plain Diff
First draft for auto commit helper
parent
557dc688
No related branches found
No related tags found
1 merge request
!113
First draft for auto commit helper
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
qutil/git.py
+86
-0
86 additions, 0 deletions
qutil/git.py
with
86 additions
and
0 deletions
qutil/git.py
0 → 100644
+
86
−
0
View file @
2ce50009
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 14 18:36:43 2023
@author: Simon Humpohl
"""
from
dataclasses
import
dataclass
from
pathlib
import
Path
import
logging
import
tkinter
from
subprocess
import
check_output
,
check_call
try
:
import
git
except
ImportError
:
git
=
None
@dataclass
class
SimpleRepo
:
"""
Re-implementation of the GitPython functionality that we use
"""
repo_path
:
Path
@property
def
name
(
self
):
return
self
.
repo_path
.
name
def
get_status
(
self
)
->
str
:
"""
Returns modified/untracked files and submodules
"""
check_output
([
'
git
'
,
'
status
'
,
'
--short
'
],
cwd
=
self
.
repo_path
)
def
add_all
(
self
):
check_call
([
'
git
'
,
'
add
'
,
'
--all
'
],
cwd
=
self
.
repo_path
)
def
commit_staged_changes
(
self
,
msg
):
check_call
([
'
git
'
,
'
commit
'
,
'
-m
'
,
msg
],
cwd
=
self
.
repo_path
)
def
get_submodules
(
self
):
sms
=
check_output
([
'
git
'
,
'
submodule
'
],
cwd
=
self
.
repo_path
).
splitlines
()
folders
=
[]
for
sm
in
sms
.
trim
():
hash_val
,
folder
,
*
_
=
sm
.
trim
().
split
()
folders
.
append
(
SimpleRepo
(
Path
(
folder
).
absolute
()))
return
folders
def
current_hash
(
self
):
raise
NotImplementedError
(
'
todo
'
)
def
auto_commit
(
repo
:
SimpleRepo
):
msg
=
'
Automatic commit. Lets hope this is nothing that needs explanation.
'
repo
.
add_all
()
repo
.
commit_staged_changes
(
msg
)
def
manual_commit
(
repo
:
SimpleRepo
,
name
:
str
):
while
status
:
=
repo
.
get_status
():
title
=
f
'
Manual commit:
{
name
}
'
msg
=
(
f
'
The repository
{
repo
.
name
}
is dirty.
'
'
Commit, ignore or stash the changes and press OK.
'
'
Pressing cancel will raise a KeyboardInterrupt.
\n\n
'
f
'
{
status
}
'
)
if
not
tkinter
.
messagebox
.
askokcancel
(
title
,
msg
):
raise
KeyboardInterrupt
(
name
)
class
GitRules
:
auto_commit
:
set
auto_push
:
dict
def
process
(
self
,
repo
:
SimpleRepo
):
if
not
repo
.
get_status
():
return
for
sm
in
repo
.
get_submodules
():
self
.
process
(
sm
)
if
not
repo
.
get_status
():
return
if
repo
.
repo_path
in
auto_commit
:
auto_commit
(
repo
)
else
:
manual_commit
(
repo
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment