Sublime Forum

How do you remove or change target paths of submodules?

#1

Hi guys,

How can I remove easily a submodule within sublime_merge? To do that usually I’m still using the command line, ie:

# Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule

# Remove the submodule directory from the superproject's .git/modules directory
rm -rf .git/modules/path/to/submodule

# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule

Usually 2 typical operations to me when working with submodules are “delete a submodule” and “change the path of an existing submodule”, could these ones be added as a sidebar command (or just a command) in sublime_merge? Right now the operations i see are:

image

and

image

Not sure if i can add these operations to these contextual menus somehow?

0 Likes

#2

I believe you can add it. The menu in your first picture is rendered by Submodule Section.sublime-menu and the second one by Submodule.sublime-menu. So in order to add an entry to delete a particular sub module, you need to create a Submodule.sublime-menu file Packages/User (Use Preferences -> Browse Packages) and add the following

[
    {
        "caption": "Delete Submodule",
        "command": "chain",
        "args": {
            "commands": [
                { "command": "git", "args": { "argv": ["submodule", "deinit", "-f", "$submodule_path"]  } },
                { "command": "git", "args": { "argv": ["rm", "-f", "$submodule_path"] } }
            ]
        },
    },
]

image

This takes care of git submodule deinit -f path/to/submodule & git rm -f path/to/submodule. I am note sure how rm -rf .git/modules/path/to/submodule can be achieved. The delete_folder command doesn’t seem to work so maybe that part has to be done manually. Also, normally deleting anything should have a prompt to go along with it, but you can’t do it in SM for custom commands without plugin support.

“change the path of an existing submodule”

My knowledge of submodules just comes from 15 minutes browsing through YT videos & git docs (since I have never used submodules), so maybe you can tell how this could be done via the git command. Does it entail changing the submodule name, submodule path in .gitmodules & changes to submodule entry in .gitconfig & updating .git/modules folder that points to the target submodule ? I am not sure.

[submodule "Example"]
	path = example
	url = <some_repo_url>
2 Likes

#3

@UltraInstinct05 Awesome, that delete submodule command definitely is already usable!

Right now I’m trying to figure out how to use delete_folder command but no luck yet… In fact, I’m quite puzzled cos I was trying to use open_dir to verify the path but for some reason below won’t work:

{ "command": "open_dir", "args": {"dir": ".git/modules/$submodule_path"}}

But yeah, you’re absolutely right, without plugin support right now it’s kind of tricky to add/debug commands with sublime_merge (or maybe just my lack of knowledge of the tool). For instance, i don’t see a good way like sublime where you can print stuff, log_commands, etc… So this is a mix of trial & error, using builtin SM commands and reading the docs :smiley:

Regarding the rename path command… maybe this could help us somehow https://stackoverflow.com/a/6310246/3809375

0 Likes

#4

Btw, I’ve just gathered all default commands provided in SublimeMerge 2059 and here’s the list

[‘add_directory’, ‘add_remote’, ‘add_submodule’, ‘add_to_kill_ring’, ‘add_where_snippet’, ‘apply_stash’, ‘auto_complete’, ‘auto_complete_open_link’, ‘auto_indent_tag’, ‘blame’, ‘build’, ‘cancel’, ‘cancel_build’, ‘chain’, ‘checkout_branch’, ‘checkout_local_branch’, ‘cherrypick_hunk’, ‘clean_working_dir’, ‘clear_bookmarks’, ‘clear_fields’, ‘clear_location’, ‘clear_stashes’, ‘close’, ‘close_by_index’, ‘close_deleted_files’, ‘close_file’, ‘close_others_by_index’, ‘close_pane’, ‘close_selected’, ‘close_tag’, ‘close_to_right_by_index’, ‘close_transient’, ‘close_unmodified’, ‘close_unmodified_to_right_by_index’, ‘close_window’, ‘commit’, ‘commit_completion’, ‘context_menu’, ‘copy’, ‘copy_to_clipboard’, ‘create_branch’, ‘create_branch_from_remote_branch’, ‘create_tag’, ‘cut’, ‘decrease_font_size’, ‘delete_branch’, ‘delete_file’, ‘delete_remote’, ‘delete_tag’, ‘delete_tag_on_remote’, ‘delete_to_mark’, ‘delete_word’, ‘discard_all_modified’, ‘discard_file’, ‘drop_stash’, ‘duplicate_line’, ‘edit_gitflow_config’, ‘edit_settings’, ‘exit’, ‘expand_selection’, ‘expand_snippet’, ‘fetch’, ‘file_history’, ‘find_all’, ‘find_all_under’, ‘find_next’, ‘find_prev’, ‘find_under’, ‘find_under_expand’, ‘find_under_expand_skip’, ‘find_under_prev’, ‘focus_by_index’, ‘focus_group’, ‘focus_neighboring_group’, ‘focus_side_bar’, ‘focus_to_left’, ‘focus_to_right’, ‘fold’, ‘fold_by_level’, ‘fold_tag_attributes’, ‘gitflow_finish_bugfix’, ‘gitflow_finish_feature’, ‘gitflow_finish_hotfix’, ‘gitflow_finish_release’, ‘gitflow_publish_bugfix’, ‘gitflow_publish_feature’, ‘gitflow_publish_hotfix’, ‘gitflow_publish_release’, ‘gitflow_rebase_bugfix’, ‘gitflow_rebase_feature’, ‘gitflow_rebase_hotfix’, ‘gitflow_rebase_release’, ‘gitflow_rebase_support’, ‘gitflow_start_bugfix’, ‘gitflow_start_feature’, ‘gitflow_start_hotfix’, ‘gitflow_start_release’, ‘gitflow_start_support’, ‘goto_definition’, ‘goto_reference’, ‘goto_symbol_in_project’, ‘hide_all_commit_refs’, ‘hide_all_refs_except’, ‘hide_all_refs_except_refs_at_commit’, ‘hide_auto_complete’, ‘hide_overlay’, ‘hide_panel’, ‘hide_popup’, ‘hide_ref’, ‘increase_font_size’, ‘indent’, ‘init_gitflow’, ‘insert’, ‘insert_snippet’, ‘join_lines’, ‘jump_back’, ‘jump_forward’, ‘left_delete’, ‘lower_case’, ‘merge_branch’, ‘move’, ‘move_to’, ‘move_to_group’, ‘move_to_neighboring_group’, ‘navigate_to_branch’, ‘navigate_to_commit’, ‘navigate_to_context_commit’, ‘navigate_to_stash’, ‘navigate_to_tag’, ‘new_file’, ‘new_file_at’, ‘new_os_tab’, ‘new_pane’, ‘new_window’, ‘next_bookmark’, ‘next_field’, ‘next_misspelling’, ‘next_modification’, ‘next_os_tab’, ‘next_result’, ‘next_view’, ‘next_view_in_stack’, ‘noop’, ‘open_containing_folder’, ‘open_context_url’, ‘open_dir’, ‘open_dir_in_sublime_text’, ‘open_folder’, ‘open_in_editor’, ‘open_preferences’, ‘open_submodule’, ‘paste’, ‘paste_and_indent’, ‘paste_from_history’, ‘pop_stash’, ‘prev_bookmark’, ‘prev_field’, ‘prev_misspelling’, ‘prev_modification’, ‘prev_os_tab’, ‘prev_result’, ‘prev_view’, ‘prev_view_in_stack’, ‘primary_j_changed’, ‘prompt_open’, ‘prompt_open_file’, ‘prompt_save_as’, ‘prompt_select_workspace’, ‘pull’, ‘push’, ‘push_tag’, ‘rebase_branch’, ‘redo’, ‘redo_or_repeat’, ‘reindent’, ‘rename_branch’, ‘rename_path’, ‘rename_remote’, ‘reopen_last_file’, ‘replace_all’, ‘replace_next’, ‘resolve_merge_conflict’, ‘reveal_link_source’, ‘revert_diff_hunk’, ‘revert_hunk’, ‘revert_modification’, ‘right_delete’, ‘run_macro’, ‘run_macro_file’, ‘save’, ‘save_all’, ‘save_without_staging’, ‘scroll_lines’, ‘search’, ‘select’, ‘select_all’, ‘select_all_bookmarks’, ‘select_by_index’, ‘select_lines’, ‘select_to_left’, ‘select_to_mark’, ‘select_to_right’, ‘set_layout’, ‘set_line_ending’, ‘set_mark’, ‘set_preference’, ‘set_upstream’, ‘show_all_refs’, ‘show_at_center’, ‘show_command_palette’, ‘show_overlay’, ‘show_panel’, ‘show_ref’, ‘show_scope_name’, ‘single_selection’, ‘slurp_find_string’, ‘slurp_replace_string’, ‘soft_redo’, ‘soft_undo’, ‘sort_lines’, ‘split_selection_into_lines’, ‘stage_all’, ‘stage_all_modified’, ‘stage_all_unmerged’, ‘stage_all_untracked’, ‘stage_file’, ‘stash’, ‘swap_line_down’, ‘swap_line_up’, ‘swap_with_mark’, ‘switch_file’, ‘sync_submodule’, ‘take_ours’, ‘take_theirs’, ‘toggle_bookmark’, ‘toggle_case_sensitive’, ‘toggle_comment’, ‘toggle_distraction_free’, ‘toggle_full_screen’, ‘toggle_ignore_diff_whitespace’, ‘toggle_inline_diff’, ‘toggle_overwrite’, ‘toggle_preference’, ‘toggle_preserve_case’, ‘toggle_record_macro’, ‘toggle_regex’, ‘toggle_setting’, ‘toggle_side_bar’, ‘toggle_whole_word’, ‘transpose’, ‘undo’, ‘unfold’, ‘unfold_all’, ‘unindent’, ‘unselect_others’, ‘unselect_to_left’, ‘unselect_to_right’, ‘unstage_all’, ‘unstage_file’, ‘update_remote_url’, ‘update_submodule’, ‘upper_case’, ‘view_tree’, ‘wrap_block’, ‘wrap_lines’, ‘yank’]

I’ve seen 266 commands available, not sure if this will help though for the current task :slight_smile:

0 Likes

#5

It doesn’t work because SM doesn’t know which repository’s .git folder you are referring to. If you want to open the submodule present in .git/modules, we can add another entry in Submodule.sublime-menu.

{
    "caption": "Open .git/module/$submodule_name",
    "command": "open_dir",
    "args": {
        "dir": "$working_dir/.git/modules/$submodule_name",
    },
}

image
(Notice the use of $working_dir variable which tells SM to use the absolute path of the open repository)

You can’t log arbitrary stuff to the console, but you definitely can log commands, key presses etc. All you need to do is go to Preferences -> Edit Settings ... and set the setting log_commands to true. Now whenever you take an action, SM will log the action’s command (if any) to the console.

A brief summary

Description Sublime Text Sublime Merge
Logging commands sublime.log_commands(True) "log_commands": true
Logging keypresses sublime.log_input(True) "log_input": true
Logging FPS sublime.log_fps(True) "log_fps": true
Logging theme control tree sublime.log_control_tree(True) "log_control_tree": true

Shameless plug https://github.com/Sublime-Instincts/CommandsBrowser

2 Likes

#6

@UltraInstinct05 Wow, thanks a lot, you’ve packed lots of really interesting info in this thread already… I was going through the docs and I don’t see many of the interesting bits there.

For instance, it’d really useful to know which ones are all hooks a user can add commands into, right now in my user folder I’ve got just this bunch:

Commit Message.sublime-settings
Commit.sublime-menu
Default (Windows).sublime-keymap
Default.sublime-commands
Preferences.sublime-settings
Submodule Section.sublime-menu
Submodule.sublime-menu
Tag.sublime-menu

But probably that’s not the whole list :confused:

Btw, before I had this command living in my Default.sublime-commands file but now I know there is a Submodule Section.sublime-menu file I wanted to move it there but it seems it won’t be possible as when i try to execute SM won’t ask about these 2 arguments $text $text. Guess that’s not possible to accomplish? Btw, one of the problems of using below command in Default.sublime-commands was that you wouldn’t know the real name of parameters as you’ll only see $text:

[
    {
        "caption": "Add Submodule at path",
        "command": "git",
        "args": {
            "argv": ["submodule", "add", "$text", "$text"]
        }
    }
]

Anyway, I won’t go too offtopic here… coming back to research the delete_folder of the submodule now :wink:

0 Likes

#7

Really cool package, thanks! I’ve just tried and I was seeing this list

image

If you see above all the ones I’ve posted, it seems there are more than 167? Guess you’re not considering the latest versions of SM?

0 Likes

#8

The ones you listed before contains a mix of both Sublime Text & Sublime Merge commands. CommandsBrowser: Browse available Sublime Merge core commands will only list SM specific commands only (Which is only applicable for SM). Since ST & SM share a common base, a lot of ST commands probably work for SM as well. But those you will find listed in CommandsBrowser: Browse available Sublime Text core commands

The reason your list returned both ST & SM is because SM’s Default Package contains all ST resource files as well (menu, commands, keymaps etc.)

0 Likes

#9

Well, unfortunately the docs are always out of date. Each update always brings a lot to the table and unless you keenly follow the development on Discord, you tend to miss a lot of things.

It’s just like Sublime Text, you can add commands to command files, keymap files, menu files etc. If you want to know all the resource files, SM doesn’t have a View Package File like ST, so you manually need to go to where you installed SM and then Packages -> Default (zip file) and browse that.

Why do you want to manually add a Add Submodule to the command palette. SM has Add Submodule from both command palette and in the Submodule Section so there isn’t really a need to add your own unless you want to do something else ?

0 Likes

#10

Fair point, I’ll definitely take a look to all existing files in all builtin SM packages to know the whole list available where i can hook into. And yeah, if they’re generating the SM docs manually of course it’s really easy they get outdated, sure thing.

Good question :)… I created this command few months ago and at that time it was because i wasn’t too happy with the functionality provided by the existing Add Submodule? Not sure why though? Maybe i thought it wasn’t possible to specify a full relative path with that one and just the name? Dunno tbh :smiley:

Regarding deleting the folder, i went through all commands provided by your awesome CommandsBrowser package and as you said at the very beginning, it doesn’t seem like it possible to accomplish this task with the functionality offered by sublime_merge :frowning: , at least I didn’t find how to do it.

About renaming the path… it doesn’t seem like it’s possible to input custom user parameters on neither Submodule Section.sublime-menu nor Submodule.sublime-menu hooks, right?

0 Likes

#11

Well, rm -rf .git/modules/path/to/submodule is about deleting, right ? So delete_folder is the only option. If it doesn’t work, maybe you are out of luck (Unless git has a way to do it)

The thing is, I am not sure how renaming submodule works :slight_smile: If you can provide a command line git example of how you do it, I can try to translate it to a menu item.

0 Likes

#12

Hehe, yeah, unfortunately I think I’m out of luck :wink: . Yet another situation where all of us would benefit of having both ST&SM open sourced, we (the whole community) would be able to dispatch these issues in no time, being able to reduce the number of massive existing pending issues from the issue tracker, etc… Not going down into the “why ST is not open source” rabbit hole again, it’s what it is :slight_smile:

Although I’ve always wondered, would have VsCode been able to win the battle against Sublime if the later would have decided to open source many years ago? You never know but I’ve always thought the foundation of Sublime has always been much much stronger than the Electron editor… IMHO the only it failed was the workhorse power… They wanted to keep it as a small familiar cozy company and that’s fair enough :slight_smile: . Not everybody wants to become McDonalds like.

I’ll experiment with this one today, shouldn’t be too difficult, thanks!

Btw, is there any unofficial place (like packagecontrol) where you guys keep community SM commands?

0 Likes

#13

There are lots of unconsidered variables like the time it takes to get familiar with the codebase (especially with a language like C/C++), managing open source & the community around it, future roadmap, what must & must not be added etc. Plus people always equate open source with free stuff. How do you survive if you don’t make money off of something ? Open source is notorious for burn outs, underpaid/sometimes not paid maintainers whose work is being used by billion dollar companies without fair returns to the maintainers themselves etc. Open source is not always the solution to something.

To be frank, I have never had an issue with ST/SM being closed source. It’s completely the company & Jon’s decision and they have the full rights to decide what’s best for the software they made. IMHO comparing VS Code & Sublime Text at this point is like comparing apples & oranges. With every update, VS Code tends to lean more on the IDE side, whereas ST will always remain a super fast text editor. Both have it’s strong points & weaknesses and I always say to use whichever is the best tool for the job. If VS Code brings food on the table, definitely go for it :slight_smile:

Sublime Merge doesn’t have a package manager like system unlike ST does (PC). So it’s just manually shared or if the functionality resides in a git package, cloned to Packages for SM

1 Like

#14

Mmm, all of those valid points. Just to be clear, I’m not criticizing decisions of Jon at all; his software, his company and his vision at the end of the day. IMHO what they’ve created over the years is a pretty awesome piece of software that has brought a lot of joy to many of us for many years (been happy user of ST since ~2012).

My main point was sometimes you’d love to see some of the issues to be delivered faster but they’re down behind the priority queue and it’s totally understandable with the size of SublimeHQ they won’t be handled & delivered for a while, nothing wrong about it. Obviously, if such tools were open source (many of us in the community c/c++ develoepers) would be able to speed up for sure the releases, as simple as that.

Now, how would you create a sustainable business by open-sourcing? Easier said than done… I don’t know… Anyway, sorry for going too offtopic here but this has always been a very interesting subject over the years :wink:

About your analogy of comparing apples & oranges I think you’re absolutely right, at this point both products have diverged quite a lot so it doesn’t make sense any longer such comparison.

0 Likes

#15

Never said you did :slight_smile: Just putting that the reality can be different sometimes.

I’d love for more issues being fixed as well (& sometimes my pet issues being addressed :wink:) but I understand they totally have to prioritize over issues that affect masses especially since it’s just 2 people working on ST.

1 Like

#16

Oh, is that so? Weren’t there 4 developers few months ago? I haven’t surfed the forums/irc for a while so I didn’t know, sad to hear that :frowning:

0 Likes

#17

AFAIK, 2 work on ST, 2 on SM (excluding Jon) I don’t know if Jon does active development work. Maybe he just oversees everything nowadays. And then 1 for product support. Will used to work, but he left the job a few months back. I heard they were recruiting but don’t have any details apart from that.

0 Likes

#18

Wow, that definitely hurts, Will was not only a very nice & really helpful guy but also an invaluable member of the team ( saw working at Uber now, congrats to him! ).

About the SM hooks we’ve talked about before, i’ve just gathered all extensions from all packages

['', '.R', '.aff', '.as', '.asp', '.bat', '.c', '.clj', '.cpp', '.cs', '.css', '.d', '.dic', '.dot', '.erb', '.erl', '.go', '.groovy', '.hidden-color-scheme', '.hidden-tmLanguage', '.hs', '.html', '.java', '.js', '.json', '.jsp', '.jsx', '.lisp', '.lua', '.m', '.mak', '.md', '.ml', '.mm', '.pas', '.php', '.pl', '.plist', '.png', '.properties', '.rb', '.re', '.rs', '.rst', '.scala', '.sh', '.sql', '.sublime-build', '.sublime-color-scheme', '.sublime-commands', '.sublime-completions', '.sublime-file-patterns', '.sublime-keymap', '.sublime-macro', '.sublime-menu', '.sublime-mousemap', '.sublime-package', '.sublime-settings', '.sublime-snippet', '.sublime-syntax', '.sublime-theme', '.tcl', '.tex', '.textile', '.tmLanguage', '.tmPreferences', '.tmTheme', '.tmpreferences', '.ts', '.tsx', '.txt', '.xml', '.yaml', '.yaws', '.yml']

So no additional ones coming from there, here’s the list I’ve got in my user folder so far:

Branches Section.sublime-menu <- Not working
Branches.sublime-menu <- Not working
Commit Message.sublime-settings
Commit.sublime-menu
Default (Windows).sublime-keymap
Default.sublime-commands
Preferences.sublime-settings
Remotes Section.sublime-menu <- Not working
Remotes.sublime-menu <- Not working
Submodule Section.sublime-menu
Submodule.sublime-menu
Tag Section.sublime-menu
Tag.sublime-menu

Branches* and Remotes* must be called something different.

0 Likes

#19

Never mind, found it https://www.sublimemerge.com/docs/menus#entries

0 Likes

#20

No, those are coming from other zip folders in Packages (which also includes language packs which can be ignored). You need to check only 2 zip folders Default & Default - Merge

For example, this is my SM installation path C:\Sublime Merge\Packages, so the 2 zip folders will be C:\Sublime Merge\Packages\Default.sublime-package & C:\Sublime Merge\Packages\Default - Merge.sublime-package.

0 Likes