git_cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ # Copyright (C) 2020 Chris Liaw <chrisliaw@antrapol.com>
2
+ # Author: Chris Liaw <chrisliaw@antrapol.com>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+
18
+
19
+ require 'fileutils'
20
+
21
+ require_relative 'global'
22
+
23
+ module GitCli
24
+ module Init
25
+
26
+ def init(path)
27
+ # from Core module
28
+ gpath = exe_path
29
+
30
+ cmd = []
31
+ #cmd << "cd #{File.expand_path(path)}"
32
+ #cmd << "&&"
33
+ cmd << gpath
34
+ cmd << "init"
35
+ cmd << File.expand_path(path)
36
+
37
+ cmdln = cmd.join(" ")
38
+
39
+ log_debug "Init : #{cmdln} "
40
+
41
+ os_exec(cmdln) do |st, res|
42
+ [st.success?, res.strip]
43
+ end
44
+
45
+ end # init
46
+
47
+ def reset(path)
48
+
49
+ raise_if_empty(path, "Path should not be empty for reset operation", GitCliException)
50
+
51
+ if File.exist?(path)
52
+ Dir.entries(path).each do |f|
53
+ if f == ".git"
54
+ log_debug ".git directory found."
55
+ FileUtils.rm_rf(f)
56
+ log_debug ".git directory deleted"
57
+ break
58
+ end
59
+ end
60
+ end
61
+
62
+ end # reset
63
+
64
+ end
65
+ end
@@ -0,0 +1,96 @@
1
+ # Copyright (C) 2020 Chris Liaw <chrisliaw@antrapol.com>
2
+ # Author: Chris Liaw <chrisliaw@antrapol.com>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+
18
+
19
+ module GitCli
20
+ module Log
21
+
22
+ SIMPLE_LOG_DEFAULT_CONF = {
23
+ args: nil, # args shall override ALL elements
24
+ limit: "50",
25
+ since: nil, # log since/after this value
26
+ until: nil, # log until/before this value
27
+ committed_by: nil, # author of the commit. If given array shall be multiple
28
+ format: "--oneline --pretty=format:\"%H | %ad | %an,%ce | %s | %b | %N\"",
29
+ }
30
+
31
+ def logs(opts = { })
32
+
33
+ check_vcs
34
+
35
+ vopts = SIMPLE_LOG_DEFAULT_CONF.merge(opts)
36
+
37
+ cmd = []
38
+ cmd << "cd"
39
+ cmd << @wsPath
40
+ cmd << "&&"
41
+ cmd << @vcs.exe_path
42
+ cmd << "log"
43
+
44
+ if not (vopts[:args].nil? or vopts[:args].empty?)
45
+ cmd << vopts[:args]
46
+ else
47
+ cmd << "-n #{vopts[:limit]}" if not_empty?(vopts[:limit])
48
+ cmd << "--since=#{vopts[:since]}" if not_empty?(vopts[:since])
49
+ cmd << "--until=#{vopts[:until]}" if not_empty?(vopts[:until])
50
+ cmd << "--committer=#{vopts[:committed_by]}" if not_empty?(vopts[:committed_by])
51
+ cmd << vopts[:format] if not_empty?(vopts[:format])
52
+ end
53
+
54
+ cmdln = cmd.join(" ")
55
+ log_debug "Logs : #{cmdln} "
56
+
57
+ res = os_exec(cmdln) do |st, res|
58
+
59
+ if st.success?
60
+ [true, res.strip!]
61
+ else
62
+ [false, res]
63
+ end
64
+ end
65
+
66
+ end # log
67
+
68
+ def show_log(cid)
69
+
70
+ check_vcs
71
+
72
+ raise_if_empty(cid, "Commit ID must be present for detail log discovery", GitCliException)
73
+ cmd = []
74
+ cmd << "cd"
75
+ cmd << @wsPath
76
+ cmd << "&&"
77
+ cmd << @vcs.exe_path
78
+ cmd << "show"
79
+ cmd << cid
80
+
81
+ cmdln = cmd.join(" ")
82
+ log_debug "Show : #{cmdln}"
83
+
84
+ res = os_exec(cmdln) do |st, res|
85
+
86
+ if st.success?
87
+ [true, res.strip!]
88
+ else
89
+ [false, res]
90
+ end
91
+ end
92
+
93
+ end # show
94
+
95
+ end
96
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright (C) 2020 Chris Liaw <chrisliaw@antrapol.com>
2
+ # Author: Chris Liaw <chrisliaw@antrapol.com>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+
18
+ require 'toolrack'
19
+
20
+ require_relative '../../global'
21
+
22
+ module GitCli
23
+ module OS
24
+ module Linux
25
+ module Utils
26
+
27
+ def Utils.is_installed?(binary)
28
+
29
+ if is_which_installed?
30
+
31
+ begin
32
+ GitCli::Global.instance.logger.debug "Checking if '#{binary}' is installed..."
33
+ res = Antrapol::ToolRack::ProcessUtilsEngine.exec("which #{binary}")
34
+ GitCli::Global.instance.logger.debug "Yes, '#{binary}' is found in system"
35
+ [true, res.strip]
36
+ rescue Exception => ex
37
+ GitCli::Global.instance.logger.debug "No, '#{binary}' is not found in system"
38
+ [false, ex.message]
39
+ end
40
+
41
+ else
42
+ raise GitCliException, "Utility 'which' is not installed"
43
+ end
44
+ end # is_installed?
45
+
46
+ private
47
+ def Utils.is_which_installed?
48
+ begin
49
+ GitCli::Global.instance.logger.debug "Checking if 'which' is installed..."
50
+ Antrapol::ToolRack::ProcessUtilsEngine.exec("which")
51
+ GitCli::Global.instance.logger.debug "'which' utility is installed..."
52
+ true
53
+ rescue Exception => ex
54
+ GitCli::Global.instance.logger.debug "'which' utility is NOT installed..."
55
+ false
56
+ end
57
+ end # is_which_installed?
58
+
59
+ end
60
+ end
61
+ end
62
+ end
File without changes
File without changes
@@ -0,0 +1,48 @@
1
+ # Copyright (C) 2020 Chris Liaw <chrisliaw@antrapol.com>
2
+ # Author: Chris Liaw <chrisliaw@antrapol.com>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+
18
+
19
+ module GitCli
20
+ module Pull
21
+
22
+ def pull(repos, branch = "master")
23
+ check_vcs
24
+ #check_repos
25
+ raise_if_empty(repos, "Pull from repository name cannot be empty", GitCliException)
26
+
27
+ raise_if_false(is_repos_exist?(repos), "Given repository name '#{repos}' is not configured for this workspace", GitCliException)
28
+
29
+ cmd = []
30
+ cmd << "cd"
31
+ cmd << @wsPath
32
+ cmd << "&&"
33
+ cmd << @vcs.exe_path
34
+ cmd << "pull"
35
+ cmd << repos
36
+ cmd << branch
37
+
38
+ cmdln = cmd.join " "
39
+
40
+ log_debug "Pull : #{cmdln}"
41
+ os_exec(cmdln) do |st, res|
42
+ [st.success?, res.strip]
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,76 @@
1
+ # Copyright (C) 2020 Chris Liaw <chrisliaw@antrapol.com>
2
+ # Author: Chris Liaw <chrisliaw@antrapol.com>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+
18
+
19
+ module GitCli
20
+ module Push
21
+
22
+ def push_changes(repos, branch = "master")
23
+ check_vcs
24
+ #check_repos
25
+ raise_if_empty(repos, "Push to repository name cannot be empty", GitCliException)
26
+
27
+ raise_if_false(is_repos_exist?(repos), "Given repository name '#{repos}' is not configured for this workspace", GitCliException)
28
+
29
+ cmd = []
30
+ cmd << "cd"
31
+ cmd << @wsPath
32
+ cmd << "&&"
33
+ cmd << @vcs.exe_path
34
+ cmd << "push"
35
+ cmd << repos
36
+ cmd << branch
37
+
38
+ cmdln = cmd.join " "
39
+
40
+ log_debug "Push : #{cmdln}"
41
+ os_exec(cmdln) do |st, res|
42
+ [st.success?, res.strip]
43
+ end
44
+ end # push_changes
45
+ alias :push :push_changes
46
+
47
+ def push_changes_with_tags(repos, branch = "master")
48
+ check_vcs
49
+ #check_repos
50
+ raise_if_empty(repos, "Push to repository name cannot be empty", GitCliException)
51
+
52
+ raise_if_false(is_repos_exist?(repos), "Given repository name '#{repos}' is not configured for this workspace", GitCliException)
53
+
54
+ cmd = []
55
+ cmd << "cd"
56
+ cmd << @wsPath
57
+ cmd << "&&"
58
+ cmd << @vcs.exe_path
59
+ cmd << "push"
60
+ cmd << repos
61
+ cmd << branch
62
+ cmd << "--tags"
63
+
64
+ cmdln = cmd.join " "
65
+
66
+ log_debug "Push with tags : #{cmdln}"
67
+ os_exec(cmdln) do |st, res|
68
+ [st.success?, res.strip]
69
+ end
70
+ end # push_changes_with_tags
71
+ alias :push_with_tags :push_changes_with_tags
72
+ alias :push_with_tag :push_changes_with_tags
73
+ alias :push_changes_with_tag :push_changes_with_tags
74
+
75
+ end
76
+ end
@@ -0,0 +1,117 @@
1
+ # Copyright (C) 2020 Chris Liaw <chrisliaw@antrapol.com>
2
+ # Author: Chris Liaw <chrisliaw@antrapol.com>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+
18
+
19
+ module GitCli
20
+ module Repos
21
+
22
+ def remote_config
23
+ check_vcs
24
+
25
+ cmd = []
26
+ cmd << "cd"
27
+ cmd << @wsPath
28
+ cmd << "&&"
29
+ cmd << @vcs.exe_path
30
+ cmd << "remote -vv"
31
+
32
+ cmdln = cmd.join(" ")
33
+ log_debug "Remote config : #{cmdln}"
34
+ res = os_exec(cmdln) do |st, res|
35
+
36
+ if st.success?
37
+
38
+ remotes = { }
39
+ res.each_line do |l|
40
+ ls = l.split("\t")
41
+ lss = ls[1].split(" ")
42
+ if not remotes.keys.include?(ls[0])
43
+ remotes[ls[0]] = lss[0]
44
+ end
45
+ end
46
+
47
+ [true, remotes]
48
+ else
49
+ [false, res]
50
+ end
51
+ end
52
+
53
+ end # remote_config
54
+
55
+ def add_remote(name, url)
56
+
57
+ raise_if_empty(name, "Remote name cannot be empty to add", GitCliException)
58
+ raise_if_empty(url, "Remote URL cannot be empty to add", GitCliException)
59
+
60
+ check_vcs
61
+
62
+ cmd = []
63
+ cmd << "cd"
64
+ cmd << @wsPath
65
+ cmd << "&&"
66
+ cmd << @vcs.exe_path
67
+ cmd << "remote"
68
+ cmd << "add"
69
+ cmd << name
70
+ cmd << url
71
+
72
+ cmdln = cmd.join(" ")
73
+ log_debug "Add remote config : #{cmdln}"
74
+ res = os_exec(cmdln) do |st, res|
75
+
76
+ if st.success?
77
+ [true, res.strip]
78
+ else
79
+ [false, res.strip]
80
+ end
81
+ end
82
+
83
+
84
+ end # add_remote
85
+
86
+ def remove_remote(name)
87
+
88
+ raise_if_empty(name, "Remote name cannot be empty to remove", GitCliException)
89
+
90
+ check_vcs
91
+
92
+ cmd = []
93
+ cmd << "cd"
94
+ cmd << @wsPath
95
+ cmd << "&&"
96
+ cmd << @vcs.exe_path
97
+ cmd << "remote"
98
+ cmd << "remove"
99
+ cmd << name
100
+
101
+ cmdln = cmd.join(" ")
102
+ log_debug "Remove remote config : #{cmdln}"
103
+ res = os_exec(cmdln) do |st, res|
104
+
105
+ if st.success?
106
+ [true, res.strip]
107
+ else
108
+ [false, res.strip]
109
+ end
110
+ end
111
+
112
+ end # remove_remote
113
+
114
+
115
+
116
+ end
117
+ end