11 Getting more information from the user
11 Getting more information from the user
Command:
1
$ git log -p
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
commit 033f27a8196987d61c4fd42930f2148b23434a03 (HEAD -> master)
Author: My name <artwalker@example.com>
Date: Mon Jul 15 14:39:18 2023 +0200
Call check_reboot from main, exit with 1 on error
diff --git a/all_checks.py b/all_checks.py
index 340f1f7..710266a 100644
--- a/all_checks.py
+++ b/all_checks.py
@@ -1,12 +1,15 @@
#!/usr/bin/env python3
import os
+import sys
def check_reboot():
"""Returns True if the computer has a pending reboot."""
return os.path.exists("/run/reboot-required")
(...)
Command:
1
$ git log
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
commit 033f27a8196987d61c4fd42930f2148b23434a03 (HEAD -> master)
Author: My name <artwalker@example.com>
Date: Mon Jul 15 14:39:18 2023 +0200
Call check_reboot from main, exit with 1 on error
commit cc1acbf10fdea6cc07ebf827697666b6a35b0f36
Author: My name <artwalker@example.com>
Date: Thu Jul 11 17:19:32 2023 +0200
Add a check_reboot function
(...)
Command:
1
$ git show cc1acbf10fdea6cc07ebf827697666b6a35b0f36
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
commit cc1acbf10fdea6cc07ebf827697666b6a35b0f36
Author: My name <artwalker@example.com>
Date: Thu Jul 11 17:19:32 2023 +0200
Add a check_reboot function
diff --git a/all_checks.py b/all_checks.py
index c0d03b3..340f1f7 100644
--- a/all_checks.py
+++ b/all_checks.py
@@ -1,5 +1,11 @@
#!/usr/bin/env python3
+import os
+
+def check_reboot():
+ """Returns True if the computer has a pending reboot."""
+ return os.path.exists("/run/reboot-required")
+
def main():
Pass
Command:
1
$ git log --stat
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
commit 033f27a8196987d61c4fd42930f2148b23434a03 (HEAD -> master)
Author: My name <artwalker@example.com>
Date: Mon Jul 15 14:39:18 2023 +0200
Call check_reboot from main, exit with 1 on error
all_checks.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(...)
Command:
1
$ vim all_checks.py
File with code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python3
import os
import sys
def check_reboot():
"""Returns True if the computer has a pending reboot."""
return os.path.exists("/run/reboot-required")
def main():
if check_reboot():
print("Pending Reboot.")
sys.exit(1)
print("Everything ok.")
sys.exit(0)
main()
Command:
1
$ git diff
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
diff --git a/all_checks.py b/all_checks.py
index 710266a..fdc4476 100644
--- a/all_checks.py
+++ b/all_checks.py
@@ -12,4 +12,7 @@ def main():
print("Pending Reboot.")
sys.exit(1)
+ print("Everything ok.")
+ sys.exit(0)
+
main()
Command:
1
$ git add -p
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
diff --git a/all_checks.py b/all_checks.py
index 710266a..fdc4476 100644
--- a/all_checks.py
+++ b/all_checks.py
@@ -12,4 +12,7 @@ def main():
print("Pending Reboot.")
sys.exit(1)
+ print("Everything ok.")
+ sys.exit(0)
+
main()
Stage this hunk [y,n,q,a,d,e,?]? y
Command:
1
2
3
$ git diff
# Only show the staged changes
$ git diff --staged
Code output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
diff --git a/all_checks.py b/all_checks.py
index 710266a..fdc4476 100644
--- a/all_checks.py
+++ b/all_checks.py
@@ -12,4 +12,7 @@ def main():
print("Pending Reboot.")
sys.exit(1)
+ print("Everything ok.")
+ sys.exit(0)
+
main()
Command:
1
$ git commit -m 'Add a message when everything is ok'
Code output:
1
2
3
[master 49d610b] Add a message when everything is ok
1 file changed, 3 insertions(+)
This post is licensed under CC BY 4.0 by the author.