@@ -68,22 +68,72 @@ def copy_paths(paths):
6868 cp (copy_from , copy_to )
6969 copied_count += 1
7070
71- ######################################## [execute git diff-tree]
71+ def get_last_commit ():
72+ if not os .path .isfile (CURRENT_PATH + '/' + '.gitccpy.lastcommit' ): return None
73+ with open (CURRENT_PATH + '/' + '.gitccpy.lastcommit' , 'r' ) as f :
74+ return f .read ()
75+
76+ def store_last_commit (id ):
77+ with open (CURRENT_PATH + '/' + '.gitccpy.lastcommit' , 'w' ) as f :
78+ f .write (id )
79+
80+ ######################################## [read last commit if exists, if user not specified custom commit id]
81+
82+ from_last_commit = False
7283
73- git_command = ['git' , 'diff-tree' , '--no-commit-id' , '--name-only' , '-r' , COMMIT_ID ]
84+ if COMMIT_ID == 'HEAD' :
85+ id = get_last_commit ()
86+ if not id == None :
87+ COMMIT_ID = id
88+ from_last_commit = True
89+
90+ ######################################## [execute git rev-list] [for retrive all commit ids of range <given-commit-id>^..HEAD]
91+
92+ git_command = ['git' , 'rev-list' , COMMIT_ID + ('' if from_last_commit else '^' ) + '..HEAD' , '--reverse' ]
7493
7594result = subprocess .run (git_command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
7695
7796if result .returncode == 0 :
78- paths = result .stdout .splitlines ()
79-
80- clear_destination (CONFIGS ['DESTINATION_PATH' ])
81- copy_paths (paths )
97+ all_commit_ids = result .stdout .splitlines ()
98+ else :
99+ print ("Error executing git rev-list command:" )
100+ print (result .stderr )
101+ exit ()
102+
103+ if (len (all_commit_ids ) == 0 ):
104+ print ("No new commits." )
105+ exit ()
106+
107+ print ('New' , len (all_commit_ids ), 'commits there...' )
82108
83- if copied_count == 0 :
84- print ('No changes in ' , CONFIGS ['LOCAL_PREXFIX' ])
109+ ######################################## [store last commit id]
110+
111+ store_last_commit (all_commit_ids [- 1 ])
112+
113+ ######################################## [execute git diff-tree for all commits]
114+
115+ changed_paths = []
116+
117+ for id in all_commit_ids :
118+ print ("Reading changes for commit:" , id )
119+
120+ git_command = ['git' , 'diff-tree' , '--no-commit-id' , '--name-only' , '-r' , id ]
121+
122+ result = subprocess .run (git_command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
123+
124+ if result .returncode == 0 :
125+ changed_paths .extend (result .stdout .splitlines ())
85126 else :
86- print (copied_count , "files copied into" , CONFIGS ['DESTINATION_PATH' ])
127+ print ("Error executing git diff-tree command:" )
128+ print (result .stderr )
129+
130+ ######################################## [copy all changes]
131+
132+ clear_destination (CONFIGS ['DESTINATION_PATH' ])
133+
134+ copy_paths (changed_paths )
135+
136+ if copied_count == 0 :
137+ print ('No changes in ' , CONFIGS ['LOCAL_PREXFIX' ])
87138else :
88- print ("Error executing git diff-tree command:" )
89- print (result .stderr )
139+ print (copied_count , "files copied into" , CONFIGS ['DESTINATION_PATH' ])
0 commit comments