Module: GitCli::Stash
- Included in:
- Gvcs::Workspace
- Defined in:
- lib/git_cli/stash.rb
Instance Method Summary collapse
-
#stash_changes(msg, include_untracked = true) ⇒ Object
Save all the temporary changes so branch switch is possible.
-
#stash_clear ⇒ Object
stash_to_branch.
-
#stash_list ⇒ Object
List all saved temporary changes.
-
#stash_remove(id = nil) ⇒ Object
stash clear.
-
#stash_restore(id = nil) ⇒ Object
Restore the temporary changes Regardless which branch are you in.
-
#stash_restore_and_remove(id = nil) ⇒ Object
stash restore.
-
#stash_to_new_branch(branch, id = nil) ⇒ Object
stash restore.
Instance Method Details
#stash_changes(msg, include_untracked = true) ⇒ Object
Save all the temporary changes so branch switch is possible
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/git_cli/stash.rb', line 29 def stash_changes(msg, include_untracked = true) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "stash" cmd << "save" if not_empty?(msg) # have to escape the message for command line purposes msg2 = msg.gsub("\"","\\\"").gsub("\\","\\\\") cmd << msg2 end # always include untracked since the stash condition # is played using scenario under development and must # switch branch for any reasons if include_untracked cmd << "--include-untracked" end cmdln = cmd.join(" ") log_debug "Stash changes : #{cmdln}" res = os_exec(cmdln) do |st, res| [st.success?, res] end end |
#stash_clear ⇒ Object
stash_to_branch
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/git_cli/stash.rb', line 182 def stash_clear check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "stash clear" cmdln = cmd.join(" ") log_debug "Clear the stash list (all uncommitted changes lost permanently) : #{cmdln}" res = os_exec(cmdln) do |st, res| [st.success?, res] end end |
#stash_list ⇒ Object
List all saved temporary changes
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/git_cli/stash.rb', line 65 def stash_list check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "stash list" cmdln = cmd.join(" ") log_debug "Stash list : #{cmdln}" res = os_exec(cmdln) do |st, res| if st.success? list = { } res.each_line do |l| ll = l.split(": ") # first element is the stash id # 2nd element is the info on branch branch = ll[1].split(" ")[-1] list[ll[0].strip] = [branch, ll[1..-1].join(": ")] end [true, list] else [false, res] end end end |
#stash_remove(id = nil) ⇒ Object
stash clear
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/git_cli/stash.rb', line 201 def stash_remove(id = nil) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "stash drop" if not is_empty?(id) cmd << id end cmdln = cmd.join(" ") log_debug "Stash #{is_empty?(id) ? "remove" : "'#{id}' is being removed"} from list (all uncommitted changes lost permanantly): #{cmdln}" res = os_exec(cmdln) do |st, res| [st.success?, res] end end |
#stash_restore(id = nil) ⇒ Object
Restore the temporary changes Regardless which branch are you in
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git_cli/stash.rb', line 104 def stash_restore(id = nil) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "stash apply" if not is_empty?(id) cmd << id end cmdln = cmd.join(" ") log_debug "Stash apply (restore the saved state) : #{cmdln}" res = os_exec(cmdln) do |st, res| [st.success?, res] end end |
#stash_restore_and_remove(id = nil) ⇒ Object
stash restore
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/git_cli/stash.rb', line 129 def stash_restore_and_remove(id = nil) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "stash pop" if not is_empty?(id) cmd << id end cmdln = cmd.join(" ") log_debug "Stash pop (restore the saved state and delete from list) : #{cmdln}" res = os_exec(cmdln) do |st, res| [st.success?, res] end end |
#stash_to_new_branch(branch, id = nil) ⇒ Object
stash restore
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/git_cli/stash.rb', line 154 def stash_to_new_branch(branch, id = nil) raise_if_empty(branch, "Branch name must not be empty for stash to branch operation", GitCliException) check_vcs cmd = [] cmd << "cd" cmd << @wsPath cmd << "&&" cmd << @vcs.exe_path cmd << "stash branch" cmd << branch if not is_empty?(id) cmd << id end cmdln = cmd.join(" ") log_debug "Stash to new branch and delete from list : #{cmdln}" res = os_exec(cmdln) do |st, res| [st.success?, res] end end |