lllyasviel commited on
Commit
50c382b
·
1 Parent(s): 2dee1ec
Files changed (1) hide show
  1. entry_with_update.py +35 -0
entry_with_update.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ try:
2
+
3
+ import pygit2
4
+ import os
5
+
6
+ repo = pygit2.Repository(os.path.abspath(os.path.dirname(__file__)))
7
+
8
+ branch_name = repo.head.shorthand
9
+
10
+ remote_name = 'origin'
11
+ remote = repo.remotes[remote_name]
12
+
13
+ remote.fetch()
14
+
15
+ local_branch_ref = f'refs/heads/{branch_name}'
16
+ local_branch = repo.lookup_reference(local_branch_ref)
17
+
18
+ remote_reference = f'refs/remotes/{remote_name}/{branch_name}'
19
+ remote_commit = repo.revparse_single(remote_reference)
20
+
21
+ merge_result, _ = repo.merge_analysis(remote_commit.id)
22
+
23
+ if merge_result & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE:
24
+ print("Already up-to-date")
25
+ elif merge_result & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD:
26
+ local_branch.set_target(remote_commit.id)
27
+ print("Fast-forward merge")
28
+ elif merge_result & pygit2.GIT_MERGE_ANALYSIS_NORMAL:
29
+ print("Update failed - Did you modified any file?")
30
+ except Exception as e:
31
+ print('Update failed.')
32
+ print(str(e))
33
+
34
+ print('Update succeeded.')
35
+ from launch import *